Esempio n. 1
0
        /// <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);
        }
        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);
        }
Esempio n. 3
0
        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;
            }
        }
Esempio n. 4
0
        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));
        }