Exemplo n.º 1
0
        Xunit1RunSummary RunTestClass(
            string typeName,
            IList <Xunit1TestCase> testCases,
            _IMessageSink messageSink)
        {
            Guard.ArgumentValid(nameof(testCases), "testCases must contain at least one test case", testCases.Count > 0);

            var handler           = new TestClassCallbackHandler(testCases, messageSink);
            var results           = handler.TestClassResults;
            var testClassStarting = new _TestClassStarting
            {
                AssemblyUniqueID       = testCases[0].AssemblyUniqueID,
                TestClass              = typeName,
                TestClassUniqueID      = testCases[0].TestClassUniqueID,
                TestCollectionUniqueID = testCases[0].TestCollectionUniqueID
            };

            results.Continue = messageSink.OnMessage(testClassStarting);

            try
            {
                if (results.Continue)
                {
                    var methodNames = testCases.Select(tc => tc.TestMethod).ToList();
                    Executor.RunTests(typeName, methodNames, handler);
                    handler.LastNodeArrived.WaitOne();
                }
            }
            finally
            {
                var testClassFinished = new _TestClassFinished
                {
                    AssemblyUniqueID       = testClassStarting.AssemblyUniqueID,
                    ExecutionTime          = results.Time,
                    TestClassUniqueID      = testClassStarting.TestClassUniqueID,
                    TestCollectionUniqueID = testClassStarting.TestCollectionUniqueID,
                    TestsFailed            = results.Failed,
                    TestsRun     = results.Total,
                    TestsSkipped = results.Skipped
                };

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

            return(results);
        }
Exemplo n.º 2
0
    /// <summary>
    /// Runs the tests in the test class.
    /// </summary>
    /// <param name="ctxt">The context that describes the current test class</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 classSummary           = new RunSummary();
            var testCollection         = ctxt.TestCases.First().TestCollection;
            var testAssemblyUniqueID   = testCollection.TestAssembly.UniqueID;
            var testCollectionUniqueID = testCollection.UniqueID;
            var testClassUniqueID      = ctxt.TestClass.UniqueID;

            var classStarting = new _TestClassStarting
            {
                AssemblyUniqueID       = testAssemblyUniqueID,
                TestClass              = ctxt.TestClass.Class.Name,
                TestClassUniqueID      = testClassUniqueID,
                TestCollectionUniqueID = testCollectionUniqueID
            };

            if (!ctxt.MessageBus.QueueMessage(classStarting))
            {
                ctxt.CancellationTokenSource.Cancel();
                return(classSummary);
            }

            try
            {
                await AfterTestClassStartingAsync(ctxt);

                SetTestContext(ctxt, TestEngineStatus.Running);

                classSummary = await RunTestMethodsAsync(ctxt);

                SetTestContext(ctxt, TestEngineStatus.CleaningUp);

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

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

                return(classSummary);
            }
            finally
            {
                var classFinished = new _TestClassFinished
                {
                    AssemblyUniqueID       = testAssemblyUniqueID,
                    ExecutionTime          = classSummary.Time,
                    TestClassUniqueID      = testClassUniqueID,
                    TestCollectionUniqueID = testCollectionUniqueID,
                    TestsFailed            = classSummary.Failed,
                    TestsRun     = classSummary.Total,
                    TestsSkipped = classSummary.Skipped
                };

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