コード例 #1
0
ファイル: ResultSinkTests.cs プロジェクト: jbhensley/xunit
        public async ValueTask TestCollectionCleanupFailure()
        {
            var collectionStarting = new _TestCollectionStarting
            {
                AssemblyUniqueID          = assemblyID,
                TestCollectionDisplayName = "FooBar",
                TestCollectionUniqueID    = collectionID
            };
            var collectionCleanupFailure = new _TestCollectionCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages               = messages,
                StackTraces            = stackTraces,
                TestCollectionUniqueID = collectionID
            };
            var listener = Substitute.For <ITestListener>();

            await using var sink = new ResultSink(listener, 42)
                        {
                            TestRunState = TestRunState.NoTests
                        };

            sink.OnMessage(collectionStarting);
            sink.OnMessage(collectionCleanupFailure);

            AssertFailure(listener, sink.TestRunState, "Test Collection Cleanup Failure (FooBar)");
        }
コード例 #2
0
    public void TestCollectionCleanupFailure()
    {
        var collectionStarting = new _TestCollectionStarting
        {
            AssemblyUniqueID          = assemblyID,
            TestCollectionDisplayName = "FooBar",
            TestCollectionUniqueID    = collectionID
        };
        var collectionCleanupFailure = new _TestCollectionCleanupFailure
        {
            AssemblyUniqueID       = assemblyID,
            ExceptionParentIndices = exceptionParentIndices,
            ExceptionTypes         = exceptionTypes,
            Messages               = messages,
            StackTraces            = stackTraces,
            TestCollectionUniqueID = collectionID
        };
        var assemblyElement = new XElement("assembly");
        var sink            = new DelegatingXmlCreationSink(innerSink, assemblyElement);

        sink.OnMessage(collectionStarting);
        sink.OnMessage(collectionCleanupFailure);

        AssertFailureElement(assemblyElement, "test-collection-cleanup", "FooBar");
    }
コード例 #3
0
        Xunit1RunSummary RunTestCollection(
            IList <Xunit1TestCase> testCases,
            _IMessageSink messageSink)
        {
            Guard.ArgumentValid(nameof(testCases), "testCases must contain at least one test case", testCases.Count > 0);

            var collectionStarting = new _TestCollectionStarting
            {
                AssemblyUniqueID          = testCases[0].AssemblyUniqueID,
                TestCollectionClass       = null,
                TestCollectionDisplayName = $"xUnit.net v1 Tests for {assemblyFileName}",
                TestCollectionUniqueID    = testCases[0].TestCollectionUniqueID
            };

            var results = new Xunit1RunSummary
            {
                Continue = messageSink.OnMessage(collectionStarting)
            };

            try
            {
                if (results.Continue)
                {
                    foreach (var testClassGroup in testCases.GroupBy(tc => tc.TestClass))
                    {
                        var classResults = RunTestClass(testClassGroup.Key, testClassGroup.ToList(), messageSink);
                        results.Aggregate(classResults);
                        if (!classResults.Continue)
                        {
                            break;
                        }
                    }
                }
            }
            finally
            {
                var collectionFinished = new _TestCollectionFinished
                {
                    AssemblyUniqueID       = collectionStarting.AssemblyUniqueID,
                    ExecutionTime          = results.Time,
                    TestCollectionUniqueID = collectionStarting.TestCollectionUniqueID,
                    TestsFailed            = results.Failed,
                    TestsRun     = results.Total,
                    TestsSkipped = results.Skipped
                };

                results.Continue = messageSink.OnMessage(collectionFinished) && results.Continue;
            }

            return(results);
        }
コード例 #4
0
        public void TestCollectionCleanupFailure()
        {
            var collectionStarting = new _TestCollectionStarting
            {
                AssemblyUniqueID          = assemblyID,
                TestCollectionDisplayName = "FooBar",
                TestCollectionUniqueID    = collectionID
            };
            var collectionCleanupFailure = new _TestCollectionCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages               = messages,
                StackTraces            = stackTraces,
                TestCollectionUniqueID = collectionID
            };
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(collectionStarting);
            handler.OnMessage(collectionCleanupFailure);

            AssertFailureMessages(handler.Messages, "Test Collection Cleanup Failure (FooBar)");
        }
コード例 #5
0
    /// <summary>
    /// Runs the tests in the test collection.
    /// </summary>
    /// <param name="ctxt">The context that describes the current test collection</param>
    /// <returns>Returns summary information about the tests that were run.</returns>
    protected async ValueTask <RunSummary> RunAsync(TContext ctxt)
    {
        await ctxt.InitializeAsync();

        try
        {
            SetTestContext(ctxt, TestEngineStatus.Initializing);

            var collectionSummary      = new RunSummary();
            var testAssemblyUniqueID   = ctxt.TestCollection.TestAssembly.UniqueID;
            var testCollectionUniqueID = ctxt.TestCollection.UniqueID;

            var collectionStarting = new _TestCollectionStarting
            {
                AssemblyUniqueID          = testAssemblyUniqueID,
                TestCollectionClass       = ctxt.TestCollection.CollectionDefinition?.Name,
                TestCollectionDisplayName = ctxt.TestCollection.DisplayName,
                TestCollectionUniqueID    = testCollectionUniqueID
            };

            if (!ctxt.MessageBus.QueueMessage(collectionStarting))
            {
                ctxt.CancellationTokenSource.Cancel();
            }
            else
            {
                try
                {
                    await AfterTestCollectionStartingAsync(ctxt);

                    SetTestContext(ctxt, TestEngineStatus.Running);

                    collectionSummary = await RunTestClassesAsync(ctxt);

                    SetTestContext(ctxt, TestEngineStatus.CleaningUp);

                    ctxt.Aggregator.Clear();
                    await BeforeTestCollectionFinishedAsync(ctxt);

                    if (ctxt.Aggregator.HasExceptions)
                    {
                        var collectionCleanupFailure = _TestCollectionCleanupFailure.FromException(ctxt.Aggregator.ToException() !, testAssemblyUniqueID, testCollectionUniqueID);
                        if (!ctxt.MessageBus.QueueMessage(collectionCleanupFailure))
                        {
                            ctxt.CancellationTokenSource.Cancel();
                        }
                    }
                }
                finally
                {
                    var collectionFinished = new _TestCollectionFinished
                    {
                        AssemblyUniqueID       = testAssemblyUniqueID,
                        ExecutionTime          = collectionSummary.Time,
                        TestCollectionUniqueID = testCollectionUniqueID,
                        TestsFailed            = collectionSummary.Failed,
                        TestsRun     = collectionSummary.Total,
                        TestsSkipped = collectionSummary.Skipped
                    };

                    if (!ctxt.MessageBus.QueueMessage(collectionFinished))
                    {
                        ctxt.CancellationTokenSource.Cancel();
                    }
                }
            }

            return(collectionSummary);
        }
        finally
        {
            await ctxt.DisposeAsync();
        }
    }