/// <summary> /// Initializes a new instance of the <see cref="IgnoreFilter"/> class. /// </summary> /// <param name="listener"> /// The listener. /// </param> public IgnoreFilter(ParallelListener listener) { this.listener = listener; }
/// <summary> /// Initializes a new instance of the <see cref="IgnoreFilter"/> class. /// </summary> /// <param name="listener"> /// The listener. /// </param> public IgnoreFilter(ParallelListener listener) { this.listener = listener; }
/// <summary> /// Runs all of the tests defined in the specified assembly, specifically not running /// any of the tests in the calling type. /// </summary> /// <param name="assemblyToTest"> /// The assembly to be tested. /// </param> /// <param name="callingType"> /// No tests will be run that are defined in this type. /// </param> /// <returns> /// The result of running the suite of tests. /// </returns> private TestResult RunTestsInParallelImpl(Assembly assemblyToTest, Type callingType) { // NUnit requires this initialization step before any tests can be run CoreExtensions.Host.InitializeService(); this.Listener = new ParallelListener(); this.Filter = new IgnoreFilter(this.Listener); List <Test> concurrentTestFixtures; try { concurrentTestFixtures = assemblyToTest.GetTypes() .Where(type => callingType != type && TestFixtureBuilder.CanBuildFrom(type)) .Select(TestFixtureBuilder.BuildFrom) .ToList(); } catch (ReflectionTypeLoadException ex) { Console.WriteLine("ReflectionTypeLoadException caught..."); foreach (Exception loaderException in ex.LoaderExceptions) { Console.WriteLine("Loader Exception --------------------"); Console.WriteLine("Message:{0}", loaderException.Message); if (loaderException is FileNotFoundException) { Console.WriteLine((loaderException as FileNotFoundException).FusionLog); } Console.WriteLine("StackTrace: {0}", loaderException.StackTrace); } throw; } var stopwatch = new Stopwatch(); stopwatch.Start(); var currentDirectory = Path.GetDirectoryName(assemblyToTest.Location); Parallel.ForEach(concurrentTestFixtures, testFixture => { Environment.CurrentDirectory = currentDirectory; TestContext.Save(); testFixture.Run(this.Listener, this.Filter); }); stopwatch.Stop(); // Find out what the failures were var testResults = this.AllResults(this.Listener.Results) .Where(x => x.Results == null) .ToList(); var failuresAndErrors = testResults .Where(result => (result.IsFailure || result.IsError)) .ToList(); // Report the errors if there are any Console.WriteLine(); foreach (TestResult failure in failuresAndErrors) { Console.WriteLine("------------------------------------------------"); Console.WriteLine(failure.Test.TestName + " failed"); Console.WriteLine(failure.Message); Console.WriteLine(failure.StackTrace); } Console.WriteLine("================================================="); var totalErrors = testResults.Count(x => x.IsError); var totalFailures = testResults.Count(x => x.IsFailure); var totalInconclusive = testResults.Count(x => x.ResultState == ResultState.Inconclusive); var totalIgnored = testResults.Count(x => x.ResultState == ResultState.Ignored); var totalSkipped = testResults.Count(x => x.ResultState == ResultState.Skipped); var totalNotRunnable = testResults.Count(x => x.ResultState == ResultState.NotRunnable); var totalNotRun = totalInconclusive + totalIgnored + totalSkipped + totalNotRunnable; var totalRun = testResults.Count - totalNotRun; Console.WriteLine( String.Format("Tests run: {0}, Errors: {1}, Failures: {2}, Inconclusive: {3}, Time: {4} seconds", totalRun, totalErrors, totalFailures, totalInconclusive, stopwatch.Elapsed.TotalSeconds)); Console.WriteLine(String.Format(" Not run: {0}, Invalid: {1}, Ignored: {2}, Skipped: {3}", totalNotRun, failuresAndErrors.Count, totalIgnored, totalSkipped)); Console.WriteLine("================================================="); // Build up the results for return var finalResult = new TestResult(new TestName()); foreach (var result in this.Listener.Results) { finalResult.AddResult(result); } return(finalResult); }
/// <summary> /// Runs all of the tests defined in the specified assembly, specifically not running /// any of the tests in the calling type. /// </summary> /// <param name="assemblyToTest"> /// The assembly to be tested. /// </param> /// <param name="callingType"> /// No tests will be run that are defined in this type. /// </param> /// <returns> /// The result of running the suite of tests. /// </returns> private TestResult RunTestsInParallelImpl(Assembly assemblyToTest, Type callingType) { // NUnit requires this initialization step before any tests can be run CoreExtensions.Host.InitializeService(); this.Listener = new ParallelListener(); this.Filter = new IgnoreFilter(this.Listener); List<Test> concurrentTestFixtures; try { concurrentTestFixtures = assemblyToTest.GetTypes() .Where(type => callingType != type && TestFixtureBuilder.CanBuildFrom(type)) .Select(TestFixtureBuilder.BuildFrom) .ToList(); } catch (ReflectionTypeLoadException ex) { Console.WriteLine("ReflectionTypeLoadException caught..."); foreach (Exception loaderException in ex.LoaderExceptions) { Console.WriteLine("Loader Exception --------------------"); Console.WriteLine("Message:{0}", loaderException.Message); if (loaderException is FileNotFoundException) { Console.WriteLine((loaderException as FileNotFoundException).FusionLog); } Console.WriteLine("StackTrace: {0}", loaderException.StackTrace); } throw; } var stopwatch = new Stopwatch(); stopwatch.Start(); var currentDirectory = Path.GetDirectoryName(assemblyToTest.Location); Parallel.ForEach(concurrentTestFixtures, testFixture => { Environment.CurrentDirectory = currentDirectory; TestContext.Save(); testFixture.Run(this.Listener, this.Filter); }); stopwatch.Stop(); // Find out what the failures were var testResults = this.AllResults(this.Listener.Results) .Where(x => x.Results == null) .ToList(); var failuresAndErrors = testResults .Where(result => (result.IsFailure || result.IsError)) .ToList(); // Report the errors if there are any Console.WriteLine(); foreach (TestResult failure in failuresAndErrors) { Console.WriteLine("------------------------------------------------"); Console.WriteLine(failure.Test.TestName + " failed"); Console.WriteLine(failure.Message); Console.WriteLine(failure.StackTrace); } Console.WriteLine("================================================="); var totalErrors = testResults.Count(x => x.IsError); var totalFailures = testResults.Count(x => x.IsFailure); var totalInconclusive = testResults.Count(x => x.ResultState == ResultState.Inconclusive); var totalIgnored = testResults.Count(x => x.ResultState == ResultState.Ignored); var totalSkipped = testResults.Count(x => x.ResultState == ResultState.Skipped); var totalNotRunnable = testResults.Count(x => x.ResultState == ResultState.NotRunnable); var totalNotRun = totalInconclusive + totalIgnored + totalSkipped + totalNotRunnable; var totalRun = testResults.Count - totalNotRun; Console.WriteLine( String.Format("Tests run: {0}, Errors: {1}, Failures: {2}, Inconclusive: {3}, Time: {4} seconds", totalRun, totalErrors, totalFailures, totalInconclusive, stopwatch.Elapsed.TotalSeconds)); Console.WriteLine(String.Format(" Not run: {0}, Invalid: {1}, Ignored: {2}, Skipped: {3}", totalNotRun, failuresAndErrors.Count, totalIgnored, totalSkipped)); Console.WriteLine("================================================="); // Build up the results for return var finalResult = new TestResult(new TestName()); foreach (var result in this.Listener.Results) { finalResult.AddResult(result); } return finalResult; }