Ejemplo n.º 1
0
        protected virtual async Task<RunSummary> RunTestCollectionsAsync(IMessageBus messageBus, CancellationTokenSource cancellationTokenSource)
        {
            var summary = new RunSummary();

            foreach (var collectionGroup in TestCases.Cast<TTestCase>().GroupBy(tc => tc.TestCollection, TestCollectionComparer.Instance))
                summary.Aggregate(await RunTestCollectionAsync(messageBus, collectionGroup.Key, collectionGroup, cancellationTokenSource));

            return summary;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs the tests in the test collection.
        /// </summary>
        /// <returns>Returns summary information about the tests that were run.</returns>
        public async Task <RunSummary> RunAsync()
        {
            var collectionSummary = new RunSummary();

            if (!MessageBus.QueueMessage(new TestCollectionStarting(TestCases.Cast <ITestCase>(), TestCollection)))
            {
                CancellationTokenSource.Cancel();
            }
            else
            {
                try
                {
                    await AfterTestCollectionStartingAsync();

                    collectionSummary = await RunTestClassesAsync();

                    Aggregator.Clear();
                    await BeforeTestCollectionFinishedAsync();

                    if (Aggregator.HasExceptions)
                    {
                        if (!MessageBus.QueueMessage(new TestCollectionCleanupFailure(TestCases.Cast <ITestCase>(), TestCollection, Aggregator.ToException())))
                        {
                            CancellationTokenSource.Cancel();
                        }
                    }
                }
                finally
                {
                    if (!MessageBus.QueueMessage(new TestCollectionFinished(TestCases.Cast <ITestCase>(), TestCollection, collectionSummary.Time, collectionSummary.Total, collectionSummary.Failed, collectionSummary.Skipped)))
                    {
                        CancellationTokenSource.Cancel();
                    }
                }
            }

            return(collectionSummary);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs the tests in the test method.
        /// </summary>
        /// <returns>Returns summary information about the tests that were run.</returns>
        public async Task <RunSummary> RunAsync()
        {
            var methodSummary = new RunSummary();

            if (!MessageBus.QueueMessage(new TestMethodStarting(TestCases.Cast <ITestCase>(), TestMethod)))
            {
                CancellationTokenSource.Cancel();
            }
            else
            {
                try
                {
                    AfterTestMethodStarting();
                    methodSummary = await RunTestCasesAsync();

                    Aggregator.Clear();
                    BeforeTestMethodFinished();

                    if (Aggregator.HasExceptions)
                    {
                        if (!MessageBus.QueueMessage(new TestMethodCleanupFailure(TestCases.Cast <ITestCase>(), TestMethod, Aggregator.ToException())))
                        {
                            CancellationTokenSource.Cancel();
                        }
                    }
                }
                finally
                {
                    if (!MessageBus.QueueMessage(new TestMethodFinished(TestCases.Cast <ITestCase>(), TestMethod, methodSummary.Time, methodSummary.Total, methodSummary.Failed, methodSummary.Skipped)))
                    {
                        CancellationTokenSource.Cancel();
                    }
                }
            }

            return(methodSummary);
        }
Ejemplo n.º 4
0
        protected override async Task <RunSummary> RunTestCollectionsAsync(IMessageBus messageBus, CancellationTokenSource cancellationTokenSource)
        {
            if (disableParallelization)
            {
                return(await base.RunTestCollectionsAsync(messageBus, cancellationTokenSource));
            }

            var tasks = TestCases.Cast <IXunitTestCase>()
                        .GroupBy(tc => tc.TestCollection, TestCollectionComparer.Instance)
                        .Select(collectionGroup => Task.Factory.StartNew(() => RunTestCollectionAsync(messageBus, collectionGroup.Key, collectionGroup, cancellationTokenSource),
                                                                         cancellationTokenSource.Token,
                                                                         TaskCreationOptions.None,
                                                                         scheduler))
                        .ToArray();

            var summaries = await Task.WhenAll(tasks.Select(t => t.Unwrap()));

            return(new RunSummary()
            {
                Total = summaries.Sum(s => s.Total),
                Failed = summaries.Sum(s => s.Failed),
                Skipped = summaries.Sum(s => s.Skipped)
            });
        }