/// <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)); }