public void DiscoverTests(IEnumerable <string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) { if (Environment.GetEnvironmentVariable("ATTACH_DEBUGGER_CHUTZPAH") != null) { Debugger.Launch(); } ChutzpahTracer.TraceInformation("Begin Test Adapter Discover Tests"); var settingsProvider = discoveryContext.RunSettings.GetSettings(AdapterConstants.SettingsName) as ChutzpahAdapterSettingsProvider; var settings = settingsProvider != null ? settingsProvider.Settings : new ChutzpahAdapterSettings(); ChutzpahTracingHelper.Toggle(settings.EnabledTracing); var testOptions = new TestOptions { MaxDegreeOfParallelism = settings.MaxDegreeOfParallelism, ChutzpahSettingsFileEnvironments = new ChutzpahSettingsFileEnvironments(settings.ChutzpahSettingsFileEnvironments) }; ChutzpahTracer.TraceInformation("Sending discovered tests to test case discovery sink"); var callback = new ParallelRunnerCallbackAdapter(new DiscoveryCallback(logger, discoverySink)); var testCases = testRunner.DiscoverTests(sources, testOptions, callback); ChutzpahTracer.TraceInformation("End Test Adapter Discover Tests"); }
public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { ChutzpahTracer.TraceInformation("Begin Test Adapter Run Tests"); var settingsProvider = runContext.RunSettings.GetSettings(AdapterConstants.SettingsName) as ChutzpahAdapterSettingsProvider; var settings = settingsProvider != null ? settingsProvider.Settings : new ChutzpahAdapterSettings(); ChutzpahTracingHelper.Toggle(settings.EnabledTracing); var testOptions = new TestOptions { TestLaunchMode = runContext.IsBeingDebugged ? TestLaunchMode.Custom: settings.OpenInBrowser ? TestLaunchMode.FullBrowser: TestLaunchMode.HeadlessBrowser, CustomTestLauncher = runContext.IsBeingDebugged ? new VsDebuggerTestLauncher() : null, MaxDegreeOfParallelism = runContext.IsBeingDebugged ? 1 : settings.MaxDegreeOfParallelism, ChutzpahSettingsFileEnvironments = new ChutzpahSettingsFileEnvironments(settings.ChutzpahSettingsFileEnvironments) }; testOptions.CoverageOptions.Enabled = runContext.IsDataCollectionEnabled; var callback = new ParallelRunnerCallbackAdapter(new ExecutionCallback(frameworkHandle, runContext)); testRunner.RunTests(sources, testOptions, callback); ChutzpahTracer.TraceInformation("End Test Adapter Run Tests"); }
public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { ChutzpahTracer.TraceInformation("Begin Test Adapter Run Tests"); var settingsProvider = runContext.RunSettings.GetSettings(ChutzpahAdapterSettings.SettingsName) as ChutzpahAdapterSettingsService; var settings = settingsProvider != null ? settingsProvider.Settings : new ChutzpahAdapterSettings(); ChutzpahTracingHelper.Toggle(settings.EnabledTracing); var testOptions = new TestOptions { TestFileTimeoutMilliseconds = settings.TimeoutMilliseconds, TestingMode = settings.TestingMode, MaxDegreeOfParallelism = settings.MaxDegreeOfParallelism, }; testOptions.CoverageOptions.Enabled = runContext.IsDataCollectionEnabled; var callback = new ParallelRunnerCallbackAdapter(new ExecutionCallback(frameworkHandle, runContext)); testRunner.RunTests(sources, testOptions, callback); ChutzpahTracer.TraceInformation("End Test Adapter Run Tests"); }
static int RunTests(CommandLine commandLine) { var testRunner = TestRunner.Create(debugEnabled: commandLine.Debug); if (commandLine.Trace) { ChutzpahTracer.AddFileListener(); } var chutzpahAssemblyName = testRunner.GetType().Assembly.GetName(); Console.WriteLine(); Console.WriteLine("chutzpah.dll: Version {0}", chutzpahAssemblyName.Version); Console.WriteLine(); TestCaseSummary testResultsSummary = null; try { var callback = commandLine.TeamCity ? (ITestMethodRunnerCallback) new TeamCityConsoleRunnerCallback() : new StandardConsoleRunnerCallback(commandLine.Silent, commandLine.VsOutput, commandLine.ShowFailureReport); callback = new ParallelRunnerCallbackAdapter(callback); var testOptions = new TestOptions { OpenInBrowser = commandLine.OpenInBrowser, TestFileTimeoutMilliseconds = commandLine.TimeOutMilliseconds, MaxDegreeOfParallelism = commandLine.Parallelism, TestingMode = commandLine.TestMode, CoverageOptions = new CoverageOptions { Enabled = commandLine.Coverage, IncludePatterns = (commandLine.CoverageIncludePatterns ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries), ExcludePatterns = (commandLine.CoverageExcludePatterns ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) } }; if (!commandLine.Discovery) { testResultsSummary = testRunner.RunTests(commandLine.Files, testOptions, callback); ProcessTestSummaryTransformers(commandLine, testResultsSummary); } else { Console.WriteLine("Test Discovery"); var tests = testRunner.DiscoverTests(commandLine.Files, testOptions).ToList(); Console.WriteLine("\nDiscovered {0} tests", tests.Count); foreach (var test in tests) { Console.WriteLine("Test '{0}:{1}' from '{2}'", test.ModuleName, test.TestName, test.InputTestFile); } return(0); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } var failedCount = testResultsSummary.FailedCount; if (commandLine.FailOnError && testResultsSummary.Errors.Any()) { return(failedCount > 0 ? failedCount : 1); } return(failedCount); }
static int RunTests(CommandLine commandLine, IEnumerable <SummaryTransformer> transformers) { var testRunner = TestRunner.Create(debugEnabled: commandLine.Debug); if (commandLine.Trace) { ChutzpahTracer.AddFileListener(); } Console.WriteLine(); TestCaseSummary testResultsSummary = null; try { var callback = commandLine.TeamCity ? (ITestMethodRunnerCallback) new TeamCityConsoleRunnerCallback() : new StandardConsoleRunnerCallback(commandLine.Silent, commandLine.VsOutput, commandLine.ShowFailureReport, commandLine.FailOnError); callback = new ParallelRunnerCallbackAdapter(callback); var testOptions = new TestOptions { TestLaunchMode = commandLine.OpenInBrowser ? TestLaunchMode.FullBrowser : TestLaunchMode.HeadlessBrowser, Engine = commandLine.Engine, OpenInBrowserName = commandLine.BrowserName, OpenInBrowserArgs = commandLine.BrowserArgs, TestFileTimeoutMilliseconds = commandLine.TimeOutMilliseconds, ChutzpahSettingsFileEnvironments = commandLine.SettingsFileEnvironments, Proxy = commandLine.Proxy, CoverageOptions = new CoverageOptions { Enabled = commandLine.Coverage, IncludePatterns = (commandLine.CoverageIncludePatterns ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries), ExcludePatterns = (commandLine.CoverageExcludePatterns ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries), IgnorePatterns = (commandLine.CoverageIgnorePatterns ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) } }; if (commandLine.Parallelism > 0) { testOptions.MaxDegreeOfParallelism = commandLine.Parallelism; } if (!commandLine.Discovery) { testResultsSummary = testRunner.RunTests(commandLine.Files, testOptions, callback); ProcessTestSummaryTransformers(transformers, commandLine, testResultsSummary); } else { Console.WriteLine("Test Discovery"); var tests = testRunner.DiscoverTests(commandLine.Files, testOptions).ToList(); Console.WriteLine("\nDiscovered {0} tests", tests.Count); foreach (var test in tests) { Console.WriteLine("Test '{0}:{1}' from '{2}'", test.ModuleName, test.TestName, test.InputTestFile); } return(0); } } catch (ArgumentException ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.ResetColor(); } if (testRunner.ActiveWebServerHost != null) { Console.WriteLine("Press any key to end Chutzpah..."); Console.ReadKey(); testRunner.ActiveWebServerHost.Dispose(); } var failedCount = testResultsSummary.FailedCount; if (commandLine.FailOnError && testResultsSummary.Errors.Any()) { return(failedCount > 0 ? failedCount : 1); } return(failedCount); }