示例#1
0
        public async ValueTask TestMethodCleanupFailure()
        {
            var methodStarting = new _TestMethodStarting
            {
                AssemblyUniqueID       = assemblyID,
                TestClassUniqueID      = classID,
                TestCollectionUniqueID = collectionID,
                TestMethod             = "MyMethod",
                TestMethodUniqueID     = methodID,
            };
            var methodCleanupFailure = new _TestMethodCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages               = messages,
                StackTraces            = stackTraces,
                TestCollectionUniqueID = collectionID,
                TestClassUniqueID      = classID,
                TestMethodUniqueID     = methodID
            };
            var listener = Substitute.For <ITestListener>();

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

            sink.OnMessage(methodStarting);
            sink.OnMessage(methodCleanupFailure);

            AssertFailure(listener, sink.TestRunState, "Test Method Cleanup Failure (MyMethod)");
        }
        public void TestMethodCleanupFailure()
        {
            var methodStarting = new _TestMethodStarting
            {
                AssemblyUniqueID       = assemblyID,
                TestClassUniqueID      = classID,
                TestCollectionUniqueID = collectionID,
                TestMethod             = "MyMethod",
                TestMethodUniqueID     = methodID,
            };
            var methodCleanupFailure = new _TestMethodCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages               = messages,
                StackTraces            = stackTraces,
                TestCollectionUniqueID = collectionID,
                TestClassUniqueID      = classID,
                TestMethodUniqueID     = methodID
            };
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(methodStarting);
            handler.OnMessage(methodCleanupFailure);

            AssertFailureMessages(handler.Messages, "Test Method Cleanup Failure (MyMethod)");
        }
    public void TestMethodCleanupFailure()
    {
        var methodStarting = new _TestMethodStarting
        {
            AssemblyUniqueID       = assemblyID,
            TestClassUniqueID      = classID,
            TestCollectionUniqueID = collectionID,
            TestMethod             = "MyMethod",
            TestMethodUniqueID     = methodID,
        };
        var methodCleanupFailure = new _TestMethodCleanupFailure
        {
            AssemblyUniqueID       = assemblyID,
            ExceptionParentIndices = exceptionParentIndices,
            ExceptionTypes         = exceptionTypes,
            Messages               = messages,
            StackTraces            = stackTraces,
            TestCollectionUniqueID = collectionID,
            TestClassUniqueID      = classID,
            TestMethodUniqueID     = methodID
        };
        var assemblyElement = new XElement("assembly");
        var sink            = new DelegatingXmlCreationSink(innerSink, assemblyElement);

        sink.OnMessage(methodStarting);
        sink.OnMessage(methodCleanupFailure);

        AssertFailureElement(assemblyElement, "test-method-cleanup", "MyMethod");
    }
示例#4
0
        void SendTestCaseMessagesWhenAppropriate(Xunit1TestCase?current)
        {
            var results = TestClassResults;

            if (current != lastTestCase && lastTestCase != null)
            {
                var testCaseFinished = new _TestCaseFinished
                {
                    AssemblyUniqueID       = lastTestCase.AssemblyUniqueID,
                    ExecutionTime          = testCaseResults.Time,
                    TestCaseUniqueID       = lastTestCase.TestCaseUniqueID,
                    TestClassUniqueID      = lastTestCase.TestClassUniqueID,
                    TestCollectionUniqueID = lastTestCase.TestCollectionUniqueID,
                    TestMethodUniqueID     = lastTestCase.TestMethodUniqueID,
                    TestsFailed            = testCaseResults.Failed,
                    TestsRun     = testCaseResults.Total,
                    TestsSkipped = testCaseResults.Skipped
                };

                results.Continue = messageSink.OnMessage(testCaseFinished) && results.Continue;
                testMethodResults.Aggregate(testCaseResults);
                testCaseResults.Reset();

                if (current == null || lastTestCase.TestMethod != current.TestMethod)
                {
                    var testMethodFinished = new _TestMethodFinished
                    {
                        AssemblyUniqueID       = lastTestCase.AssemblyUniqueID,
                        ExecutionTime          = testMethodResults.Time,
                        TestClassUniqueID      = lastTestCase.TestClassUniqueID,
                        TestCollectionUniqueID = lastTestCase.TestCollectionUniqueID,
                        TestMethodUniqueID     = lastTestCase.TestMethodUniqueID,
                        TestsFailed            = testMethodResults.Failed,
                        TestsRun     = testMethodResults.Total,
                        TestsSkipped = testMethodResults.Skipped
                    };

                    results.Continue = messageSink.OnMessage(testMethodFinished) && results.Continue;

                    testMethodResults.Reset();
                }
            }

            if (current != lastTestCase && current != null)
            {
                // Dispatch TestMethodStarting if we've moved onto a new method
                if (lastTestCase == null || lastTestCase.TestMethod != current.TestMethod)
                {
                    var testMethodStarting = new _TestMethodStarting
                    {
                        AssemblyUniqueID       = current.AssemblyUniqueID,
                        TestClassUniqueID      = current.TestClassUniqueID,
                        TestCollectionUniqueID = current.TestCollectionUniqueID,
                        TestMethod             = current.TestMethod,
                        TestMethodUniqueID     = current.TestMethodUniqueID
                    };
                    results.Continue = messageSink.OnMessage(testMethodStarting) && results.Continue;
                }

                // Dispatch TestCaseStarting
                var testCaseStarting = new _TestCaseStarting
                {
                    AssemblyUniqueID       = current.AssemblyUniqueID,
                    SkipReason             = current.SkipReason,
                    SourceFilePath         = current.SourceFilePath,
                    SourceLineNumber       = current.SourceLineNumber,
                    TestCaseDisplayName    = current.TestCaseDisplayName,
                    TestCaseUniqueID       = current.TestCaseUniqueID,
                    TestClassUniqueID      = current.TestClassUniqueID,
                    TestCollectionUniqueID = current.TestCollectionUniqueID,
                    TestMethodUniqueID     = current.TestMethodUniqueID,
                    Traits = current.Traits
                };

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

            lastTestCase = current;
        }
示例#5
0
    /// <summary>
    /// Runs the tests in the test method.
    /// </summary>
    /// <param name="ctxt">The context that describes the current test method</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 methodSummary          = new RunSummary();
            var testCollection         = ctxt.TestCases.First().TestCollection;
            var testAssemblyUniqueID   = testCollection.TestAssembly.UniqueID;
            var testCollectionUniqueID = testCollection.UniqueID;
            var testClassUniqueID      = ctxt.TestClass.UniqueID;
            var testMethodUniqueID     = ctxt.TestMethod.UniqueID;

            var methodStarting = new _TestMethodStarting
            {
                AssemblyUniqueID       = testAssemblyUniqueID,
                TestClassUniqueID      = testClassUniqueID,
                TestCollectionUniqueID = testCollectionUniqueID,
                TestMethod             = ctxt.TestMethod.Method.Name,
                TestMethodUniqueID     = testMethodUniqueID
            };

            if (!ctxt.MessageBus.QueueMessage(methodStarting))
            {
                ctxt.CancellationTokenSource.Cancel();
                return(methodSummary);
            }

            try
            {
                await AfterTestMethodStarting(ctxt);

                SetTestContext(ctxt, TestEngineStatus.Running);

                methodSummary = await RunTestCasesAsync(ctxt);

                SetTestContext(ctxt, TestEngineStatus.CleaningUp);

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

                if (ctxt.Aggregator.HasExceptions)
                {
                    var methodCleanupFailure = _TestMethodCleanupFailure.FromException(ctxt.Aggregator.ToException() !, testAssemblyUniqueID, testCollectionUniqueID, testClassUniqueID, testMethodUniqueID);
                    if (!ctxt.MessageBus.QueueMessage(methodCleanupFailure))
                    {
                        ctxt.CancellationTokenSource.Cancel();
                    }
                }

                return(methodSummary);
            }
            finally
            {
                var testMethodFinished = new _TestMethodFinished
                {
                    AssemblyUniqueID       = testAssemblyUniqueID,
                    ExecutionTime          = methodSummary.Time,
                    TestClassUniqueID      = testClassUniqueID,
                    TestCollectionUniqueID = testCollectionUniqueID,
                    TestMethodUniqueID     = testMethodUniqueID,
                    TestsFailed            = methodSummary.Failed,
                    TestsRun     = methodSummary.Total,
                    TestsSkipped = methodSummary.Skipped
                };

                if (!ctxt.MessageBus.QueueMessage(testMethodFinished))
                {
                    ctxt.CancellationTokenSource.Cancel();
                }
            }
        }
        finally
        {
            await ctxt.DisposeAsync();
        }
    }