/// <summary> /// Runs the list of test methods. By default, orders the tests, groups them by method and runs them synchronously. /// </summary> /// <returns>Returns summary information about the tests that were run.</returns> protected virtual async Task <RunSummary> RunTestMethodsAsync() { var summary = new RunSummary(); IEnumerable <TTestCase> orderedTestCases; try { orderedTestCases = TestCaseOrderer.OrderTestCases(TestCases); } catch (Exception ex) { var innerEx = ex.Unwrap(); DiagnosticMessageSink.OnMessage(new DiagnosticMessage($"Test case orderer '{TestCaseOrderer.GetType().FullName}' threw '{innerEx.GetType().FullName}' during ordering: {innerEx.Message}{Environment.NewLine}{innerEx.StackTrace}")); orderedTestCases = TestCases.ToList(); } var constructorArguments = CreateTestClassConstructorArguments(); foreach (var method in orderedTestCases.GroupBy(tc => tc.TestMethod, TestMethodComparer.Instance)) { summary.Aggregate(await RunTestMethodAsync(method.Key, (IReflectionMethodInfo)method.Key.Method, method, constructorArguments)); if (CancellationTokenSource.IsCancellationRequested) { break; } } return(summary); }
/// <summary> /// Runs the list of test methods. By default, orders the tests, groups them by method and runs them synchronously. /// </summary> /// <returns>Returns summary information about the tests that were run.</returns> protected virtual async Task <RunSummary> RunTestMethodsAsync() { var summary = new RunSummary(); var orderedTestCases = TestCaseOrderer.OrderTestCases(TestCases); var constructorArguments = CreateTestClassConstructorArguments(); foreach (var method in orderedTestCases.GroupBy(tc => tc.Method)) { summary.Aggregate(await RunTestMethodAsync((IReflectionMethodInfo)method.Key, method, constructorArguments)); if (CancellationTokenSource.IsCancellationRequested) { break; } } return(summary); }
public async Task <RunSummary> RunAsync() { OnTestClassStarting(); var classSummary = new RunSummary(); if (!MessageBus.QueueMessage(new TestClassStarting(TestCollection, TestClass.Name))) { CancellationTokenSource.Cancel(); } else { var orderedTestCases = TestCaseOrderer.OrderTestCases(TestCases); var methodGroups = orderedTestCases.GroupBy(tc => tc.Method); var constructorArguments = CreateTestClassConstructorArguments(); foreach (var method in methodGroups) { var methodSummary = await RunTestMethodAsync(constructorArguments, (IReflectionMethodInfo)method.Key, method); classSummary.Aggregate(methodSummary); if (CancellationTokenSource.IsCancellationRequested) { break; } } } if (!MessageBus.QueueMessage(new TestClassFinished(TestCollection, TestClass.Name, classSummary.Time, classSummary.Total, classSummary.Failed, classSummary.Skipped))) { CancellationTokenSource.Cancel(); } OnTestClassFinished(); return(classSummary); }
protected override async Task <RunSummary> RunTestMethodsAsync() { IEnumerable <IXunitTestCase> orderedTestCases; try { orderedTestCases = TestCaseOrderer.OrderTestCases(TestCases); } catch (Exception ex) { var innerEx = ex.Unwrap(); DiagnosticMessageSink.OnMessage(new DiagnosticMessage($"Test case orderer '{TestCaseOrderer.GetType().FullName}' threw '{innerEx.GetType().FullName}' during ordering: {innerEx.Message}{Environment.NewLine}{innerEx.StackTrace}")); orderedTestCases = TestCases.ToList(); } var constructorArguments = CreateTestClassConstructorArguments(); var tasks = orderedTestCases .GroupBy(tc => tc.TestMethod, TestMethodComparer.Instance) .Select(method => (Func <Task <RunSummary> >)(() => RunTestMethodAsync(method.Key, (IReflectionMethodInfo)method.Key.Method, method, constructorArguments))) .ToArray(); return(await TaskExecutor.RunAsync(CancellationTokenSource.Token, tasks, TestClass)); }
private async Task <RunSummary> RunIsolatedAsync() { IsolatedContext isolatedContext = null; TestCollectionScope scope; try { isolatedContext = new IsolatedContext(_appDomainFixtureTypes, Aggregator); scope = new TestCollectionScope(TestCollection, _meeMessageSinkWithEvents, isolatedContext, _dispositionTaskFactory, DiagnosticMessageSink); // owns the isolated instance } catch (Exception) { isolatedContext?.Dispose(); throw; } try { var remoteTestCases = isolatedContext.CreateRemoteTestCases(TestCases, _testCaseDeserializerArgs); var remoteCancellationTokenSource = isolatedContext.CreateRemoteCancellationTokenSource(CancellationTokenSource); var runnerArgs = new object[] { TestCollection, remoteTestCases, DiagnosticMessageSink, MessageBus, TestCaseOrderer.GetType(), remoteCancellationTokenSource, Aggregator.ToException() }; var runSummary = await isolatedContext.CreateRemoteInstanceAndRunAsync <RemoteTestCollectionRunner>(runnerArgs, RemoteTestCollectionRunner.MethodRunAsync); // now that the run summary is available schedule the disposition of the scope as soon as it is completed scope.DisposeOnCompletionAsync(CancellationTokenSource.Token); return(runSummary); } catch (Exception) { scope.Dispose(); throw; } }
protected async override Task <RunSummary> RunTestClassesAsync() { var groups = TestCases .GroupBy(tc => tc.TestMethod.TestClass, TestClassComparer.Instance); try { if (TestCaseOrderer is ITestClassOrderer orderer) { groups = orderer.OrderTestClasses(groups); } } catch (Exception ex) { if ((ex is TargetInvocationException tiex)) { ex = ex.InnerException; } DiagnosticMessageSink.OnMessage(new DiagnosticMessage($"Test class orderer '{TestCaseOrderer.GetType().FullName}' threw '{ex.GetType().FullName}' during ordering: {ex.Message}{Environment.NewLine}{ex.StackTrace}")); } var summary = new RunSummary(); foreach (IGrouping <ITestClass, IXunitTestCase> testCasesByClass in groups) { summary.Aggregate( await RunTestClassAsync( testCasesByClass.Key, (IReflectionTypeInfo)testCasesByClass.Key.Class, testCasesByClass)); if (CancellationTokenSource.IsCancellationRequested) { break; } } return(summary); }