Skip to content

Commit

Permalink
Added support for multiple xaps by specifying multiple -x arguments E…
Browse files Browse the repository at this point in the history
…X: '-x=file1.xap -x=file2.xap' parameters (KnownIssue: seems to be an issue if coupling multiple xaps with a --NumberOfBrowserHosts > 0 argument
  • Loading branch information
staxmanade committed Sep 23, 2010
1 parent 5181549 commit 56987d7
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 37 deletions.
7 changes: 4 additions & 3 deletions default.ps1
Expand Up @@ -681,12 +681,13 @@ Task test-specific-method-filter {

Task test-multiple-xaps {
$scriptFile = GetTemporaryXmlFile;
& "$build_dir\StatLight.exe" "-x=.\src\StatLight.IntegrationTests.Silverlight.LotsOfTests\Bin\$build_configuration\StatLight.IntegrationTests.Silverlight.LotsOfTests.xap;.\src\StatLight.IntegrationTests.Silverlight.MSTest\Bin\Debug\StatLight.IntegrationTests.Silverlight.MSTest.xap" "-o=MSTest" "-r=$scriptFile"
& "$build_dir\StatLight.exe" "-x=.\src\StatLight.IntegrationTests.Silverlight.MSTest\Bin\Debug\StatLight.IntegrationTests.Silverlight.MSTest.xap" "-x=.\src\StatLight.IntegrationTests.Silverlight.MSTest\Bin\Debug\StatLight.IntegrationTests.Silverlight.MSTest.xap" "-o=MSTest" "-r=$scriptFile"
# & "$build_dir\StatLight.exe" "-x=.\src\StatLight.IntegrationTests.Silverlight.LotsOfTests\Bin\$build_configuration\StatLight.IntegrationTests.Silverlight.LotsOfTests.xap" "-x=.\src\StatLight.IntegrationTests.Silverlight.MSTest\Bin\Debug\StatLight.IntegrationTests.Silverlight.MSTest.xap" "-o=MSTest" "-r=$scriptFile"
#"-NumberOfBrowserHosts=5"

Assert-statlight-xml-report-results -message "test-specific-method-filter" -resultsXmlTextFilePath $scriptFile -expectedPassedCount 6 -expectedFailedCount 2 -expectedIgnoredCount 1
Assert-statlight-xml-report-results -message "test-specific-method-filter" -resultsXmlTextFilePath $scriptFile -expectedPassedCount 1005 -expectedFailedCount 3 -expectedIgnoredCount 1 -expectedSystemGeneratedfailedCount 1
}


Task test-remote-access-querystring {
$hostServieWebsitePath = (Get-Item .\src\StatLight.RemoteIntegration\StatLight.RemoteIntegration.Web);

Expand Down
3 changes: 2 additions & 1 deletion src/StatLight.Core.Tests/Console/ArgOptionsTests.cs
@@ -1,4 +1,5 @@
using System.IO;
using System.Linq;
using NUnit.Framework;
using StatLight.Console;

Expand Down Expand Up @@ -32,7 +33,7 @@ public void should_be_able_to_get_the_xap_path_property_when_given_the_argument(
{
var argOptions = GetArgOptions("-x", _actualFile);

argOptions.XapPath.ShouldEqual(_actualFile);
argOptions.XapPath.First().ShouldEqual(_actualFile);
}

[Test]
Expand Down
2 changes: 2 additions & 0 deletions src/StatLight.Core/GlobalSuppressions.cs
Expand Up @@ -88,3 +88,5 @@
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.Int32.ToString", Scope = "member", Target = "StatLight.Core.WebServer.StatLightService.#GetHtmlTestPage()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "StatLight.Core.Runners.StatLightRunnerFactory.#BuildAndReturnWebServiceAndBrowser(StatLight.Core.Common.ILogger,System.Boolean,StatLight.Core.Configuration.ClientTestRunConfiguration,StatLight.Core.Configuration.ServerTestRunConfiguration,StatLight.Core.WebServer.StatLightService&,StatLight.Core.WebServer.StatLightServiceHost&,System.Collections.Generic.List`1<StatLight.Core.WebBrowser.IBrowserFormHost>&)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Postback", Scope = "member", Target = "StatLight.Core.WebServer.StatLightServiceRestApi.#StatLightResultPostbackUrl")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "ContinuousTestRunner", Scope = "member", Target = "StatLight.Core.Runners.ContinuousTestRunner.#.ctor(StatLight.Core.Common.ILogger,StatLight.Core.Events.Aggregation.IEventAggregator,StatLight.Core.WebBrowser.IBrowserFormHost,StatLight.Core.WebServer.IStatLightService,StatLight.Core.WebServer.IXapFileBuildChangedMonitor,System.String)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "ctor", Scope = "member", Target = "StatLight.Core.Runners.ContinuousTestRunner.#.ctor(StatLight.Core.Common.ILogger,StatLight.Core.Events.Aggregation.IEventAggregator,StatLight.Core.WebBrowser.IBrowserFormHost,StatLight.Core.WebServer.IStatLightService,StatLight.Core.WebServer.IXapFileBuildChangedMonitor,System.String)")]
33 changes: 33 additions & 0 deletions src/StatLight.Core/Reporting/TestReport.cs
@@ -1,4 +1,6 @@

using System.Collections;

namespace StatLight.Core.Reporting
{
using System.Collections.Generic;
Expand Down Expand Up @@ -52,6 +54,37 @@ public enum ResultType
SystemGeneratedFailure,
}

public class TestReportCollection : IEnumerable<TestReport>
{
private readonly List<TestReport> _testReports = new List<TestReport>();
public RunCompletedState FinalResult
{
get
{
if (_testReports.Any(testReport => testReport.FinalResult == RunCompletedState.Failure))
{
return RunCompletedState.Failure;
}

return RunCompletedState.Successful;
}
}

public IEnumerator<TestReport> GetEnumerator()
{
return _testReports.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

public void Add(TestReport testReport)
{
_testReports.Add(testReport);
}
}

public class TestReport
{
Expand Down
22 changes: 12 additions & 10 deletions src/Statlight.Console/ArgOptions.cs
@@ -1,5 +1,6 @@

using System.Collections.ObjectModel;
using Mono.Options;

namespace StatLight.Console
{
Expand All @@ -13,11 +14,15 @@ namespace StatLight.Console

public class ArgOptions
{
private readonly Mono.Options.OptionSet _optionSet;
private readonly OptionSet _optionSet;

private readonly string[] _args;

public string XapPath { get; private set; }
private readonly IList<string> _xapPath = new List<string>();
public IList<string> XapPath
{
get { return _xapPath; }
}

public string XmlReportOutputPath { get; private set; }

Expand Down Expand Up @@ -67,7 +72,7 @@ public ArgOptions(string[] args)
{
extra = _optionSet.Parse(_args);
}
catch (Mono.Options.OptionException e)
catch (OptionException e)
{
System.Console.Write("Error parsing arguments: ");
System.Console.WriteLine(e.Message);
Expand All @@ -76,17 +81,14 @@ public ArgOptions(string[] args)
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
private Mono.Options.OptionSet GetOptions()
private OptionSet GetOptions()
{
var msTestVersions = (from MicrosoftTestingFrameworkVersion version in Enum.GetValues(typeof(MicrosoftTestingFrameworkVersion))
select version).ToDictionary(key => key.ToString().ToLower(), value => value);

return new Mono.Options.OptionSet()
.Add("x|XapPath", "Path to test xap file.", v =>
{
XapPath = v ?? string.Empty;
}, Mono.Options.OptionValueType.Required)
.Add("t|TagFilters", "The tag filter expression used to filter executed tests. (See Microsoft.Silverlight.Testing filter format for how to generate complicated filter expressions) Only available with MSTest.", v => TagFilters = v, Mono.Options.OptionValueType.Optional)
return new OptionSet()
.Add("x|XapPath=", "Path to test xap file. (Can specify multiple -x={path1} -x={path2})", v => _xapPath.Add(v ?? string.Empty), OptionValueType.Required)
.Add("t|TagFilters", "The tag filter expression used to filter executed tests. (See Microsoft.Silverlight.Testing filter format for how to generate complicated filter expressions) Only available with MSTest.", v => TagFilters = v, OptionValueType.Optional)
.Add<string>("c|Continuous", "Runs a single test run, and then monitors the xap for build changes and re-runs the tests automatically.", v => ContinuousIntegrationMode = true)
.Add<string>("b|ShowTestingBrowserHost", "Show the browser that is running the tests - necessary to run UI specific tests (hidden by default)", v => ShowTestingBrowserHost = true)
.Add("MethodsToTest", "Semicolon seperated list of full method names to execute. EX: --methodsToTest=\"RootNamespace.ChildNamespace.ClassName.MethodUnderTest;RootNamespace.ChildNamespace.ClassName.Method2UnderTest;\"", v =>
Expand Down
60 changes: 37 additions & 23 deletions src/Statlight.Console/Program.cs
@@ -1,6 +1,8 @@


using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace StatLight.Console
{
Expand Down Expand Up @@ -39,15 +41,19 @@ static void Main(string[] args)
try
{
options = new ArgOptions(args);
if (options.ShowHelp)

IEnumerable<string> xapPaths = options.XapPath;

if (options.ShowHelp ||
!xapPaths.Any())
{
ArgOptions.ShowHelpMessage(Console.Out, options);
return;
}

ILogger logger = GetLogger(options.IsRequestingDebug);

string xapPath = options.XapPath;

bool continuousIntegrationMode = options.ContinuousIntegrationMode;
bool showTestingBrowserHost = options.ShowTestingBrowserHost;
bool useTeamCity = options.OutputForTeamCity;
Expand All @@ -71,31 +77,39 @@ static void Main(string[] args)

logger.Debug("runnerType ({0})".FormatWith(runnerType));

StatLightConfiguration statLightConfiguration = statLightConfigurationFactory
.GetStatLightConfiguration(
unitTestProviderType,
xapPath,
microsoftTestingFrameworkVersion,
methodsToTest,
tagFilters,
numberOfBrowserHosts,
useRemoteTestPage,
queryString);
var testReports = new TestReportCollection();

IRunner runner = GetRunner(
logger,
runnerType,
showTestingBrowserHost,
statLightConfiguration,
statLightRunnerFactory);

logger.Debug("IRunner typeof({0})".FormatWith(runner.GetType().Name));
foreach (var xapPath in xapPaths)
{

TestReport testReport = runner.Run();
StatLightConfiguration statLightConfiguration = statLightConfigurationFactory
.GetStatLightConfiguration(
unitTestProviderType,
xapPath,
microsoftTestingFrameworkVersion,
methodsToTest,
tagFilters,
numberOfBrowserHosts,
useRemoteTestPage,
queryString);

IRunner runner = GetRunner(
logger,
runnerType,
showTestingBrowserHost,
statLightConfiguration,
statLightRunnerFactory);

logger.Debug("IRunner typeof({0})".FormatWith(runner.GetType().Name));

TestReport testReport = runner.Run();
testReports.Add(testReport);
runner.Dispose();
}

if (!string.IsNullOrEmpty(xmlReportOutputPath))
{
var xmlReport = new XmlReport(testReport);
var xmlReport = new XmlReport(testReports.First());
xmlReport.WriteXmlReport(xmlReportOutputPath);

"*********************************"
Expand All @@ -109,7 +123,7 @@ static void Main(string[] args)
.WrapConsoleMessageWithColor(ConsoleColor.White, true);
}

if (testReport.FinalResult == RunCompletedState.Failure)
if (testReports.FinalResult == RunCompletedState.Failure)
Environment.ExitCode = ExitFailed;
else
Environment.ExitCode = ExitSucceeded;
Expand Down

0 comments on commit 56987d7

Please sign in to comment.