Пример #1
0
    public static async void TestContextInspection()
    {
        var runner = TestableTestMethodRunner.Create();

        await runner.RunAsync();

        Assert.NotNull(runner.AfterTestMethodStarting_Context);
        Assert.Equal(TestEngineStatus.Running, runner.AfterTestMethodStarting_Context.TestAssemblyStatus);
        Assert.Equal(TestEngineStatus.Running, runner.AfterTestMethodStarting_Context.TestCollectionStatus);
        Assert.Equal(TestEngineStatus.Running, runner.AfterTestMethodStarting_Context.TestClassStatus);
        Assert.Equal(TestEngineStatus.Initializing, runner.AfterTestMethodStarting_Context.TestMethodStatus);
        Assert.Equal(TestPipelineStage.TestMethodExecution, runner.AfterTestMethodStarting_Context.PipelineStage);
        Assert.Null(runner.AfterTestMethodStarting_Context.TestCaseStatus);
        Assert.Null(runner.AfterTestMethodStarting_Context.TestStatus);
        Assert.Same(runner.TestMethod, runner.AfterTestMethodStarting_Context.TestMethod);

        Assert.NotNull(runner.RunTestCaseAsync_Context);
        Assert.Equal(TestEngineStatus.Running, runner.RunTestCaseAsync_Context.TestAssemblyStatus);
        Assert.Equal(TestEngineStatus.Running, runner.RunTestCaseAsync_Context.TestCollectionStatus);
        Assert.Equal(TestEngineStatus.Running, runner.RunTestCaseAsync_Context.TestClassStatus);
        Assert.Equal(TestEngineStatus.Running, runner.RunTestCaseAsync_Context.TestMethodStatus);
        Assert.Null(runner.RunTestCaseAsync_Context.TestCaseStatus);
        Assert.Null(runner.RunTestCaseAsync_Context.TestStatus);
        Assert.Same(runner.TestMethod, runner.RunTestCaseAsync_Context.TestMethod);

        Assert.NotNull(runner.BeforeTestMethodFinished_Context);
        Assert.Equal(TestEngineStatus.Running, runner.BeforeTestMethodFinished_Context.TestAssemblyStatus);
        Assert.Equal(TestEngineStatus.Running, runner.BeforeTestMethodFinished_Context.TestCollectionStatus);
        Assert.Equal(TestEngineStatus.Running, runner.BeforeTestMethodFinished_Context.TestClassStatus);
        Assert.Equal(TestEngineStatus.CleaningUp, runner.BeforeTestMethodFinished_Context.TestMethodStatus);
        Assert.Null(runner.BeforeTestMethodFinished_Context.TestCaseStatus);
        Assert.Null(runner.BeforeTestMethodFinished_Context.TestStatus);
        Assert.Same(runner.TestMethod, runner.BeforeTestMethodFinished_Context.TestMethod);
    }
Пример #2
0
    public static async void FailureInQueueOfTestMethodStarting_DoesNotQueueTestMethodFinished_DoesNotRunTestCases()
    {
        var messages   = new List <IMessageSinkMessage>();
        var messageBus = Substitute.For <IMessageBus>();

        messageBus
        .QueueMessage(null)
        .ReturnsForAnyArgs(callInfo =>
        {
            var msg = callInfo.Arg <IMessageSinkMessage>();
            messages.Add(msg);

            if (msg is ITestMethodStarting)
            {
                throw new InvalidOperationException();
            }

            return(true);
        });
        var runner = TestableTestMethodRunner.Create(messageBus);

        await Assert.ThrowsAsync <InvalidOperationException>(() => runner.RunAsync());

        var starting = Assert.Single(messages);

        Assert.IsAssignableFrom <ITestMethodStarting>(starting);
        Assert.Empty(runner.TestCasesRun);
    }
Пример #3
0
    public static async void Messages()
    {
        var summary = new RunSummary {
            Total = 4, Failed = 2, Skipped = 1, Time = 21.12m
        };
        var messageBus = new SpyMessageBus();
        var testCase   = Mocks.TestCase <ClassUnderTest>("Passing");
        var runner     = TestableTestMethodRunner.Create(messageBus, new[] { testCase }, result: summary);

        var result = await runner.RunAsync();

        Assert.Equal(result.Total, summary.Total);
        Assert.Equal(result.Failed, summary.Failed);
        Assert.Equal(result.Skipped, summary.Skipped);
        Assert.Equal(result.Time, summary.Time);
        Assert.False(runner.TokenSource.IsCancellationRequested);
        Assert.Collection(
            messageBus.Messages,
            msg =>
        {
            var starting = Assert.IsAssignableFrom <_TestMethodStarting>(msg);
            Assert.Equal("Passing", starting.TestMethod);
        },
            msg =>
        {
            var finished = Assert.IsAssignableFrom <_TestMethodFinished>(msg);
            Assert.Equal(21.12m, finished.ExecutionTime);
            Assert.Equal(2, finished.TestsFailed);
            Assert.Equal(4, finished.TestsRun);
            Assert.Equal(1, finished.TestsSkipped);
        }
            );
    }
Пример #4
0
    public static async void RunTestCaseAsync_AggregatorIncludesPassedInExceptions()
    {
        var messageBus = new SpyMessageBus();
        var ex         = new DivideByZeroException();
        var runner     = TestableTestMethodRunner.Create(messageBus, aggregatorSeedException: ex);

        await runner.RunAsync();

        Assert.Same(ex, runner.RunTestCaseAsync_AggregatorResult);
        Assert.Empty(messageBus.Messages.OfType <ITestMethodCleanupFailure>());
    }
Пример #5
0
    public static async void Cancellation_TestMethodCleanupFailure_SetsCancellationToken()
    {
        var messageBus = new SpyMessageBus(msg => !(msg is ITestMethodCleanupFailure));
        var runner     = TestableTestMethodRunner.Create(messageBus);

        runner.BeforeTestMethodFinished_Callback = aggregator => aggregator.Add(new Exception());

        await runner.RunAsync();

        Assert.True(runner.TokenSource.IsCancellationRequested);
    }
Пример #6
0
    public static async void Cancellation_TestMethodFinished_CallsExtensibilityMethods()
    {
        var messageBus = new SpyMessageBus(msg => !(msg is ITestMethodFinished));
        var runner     = TestableTestMethodRunner.Create(messageBus);

        await runner.RunAsync();

        Assert.True(runner.TokenSource.IsCancellationRequested);
        Assert.True(runner.AfterTestMethodStarting_Called);
        Assert.True(runner.BeforeTestMethodFinished_Called);
    }
Пример #7
0
    public static async void SignalingCancellationStopsRunningMethods()
    {
        var passing = Mocks.TestCase <ClassUnderTest>("Passing");
        var other   = Mocks.TestCase <ClassUnderTest>("Other");
        var runner  = TestableTestMethodRunner.Create(testCases: new[] { passing, other }, cancelInRunTestCaseAsync: true);

        await runner.RunAsync();

        var testCase = Assert.Single(runner.TestCasesRun);

        Assert.Same(passing, testCase);
    }
Пример #8
0
    public static async void FailureInAfterTestMethodStarting_GivesErroredAggregatorToTestCaseRunner_NoCleanupFailureMessage()
    {
        var messageBus = new SpyMessageBus();
        var runner     = TestableTestMethodRunner.Create(messageBus);
        var ex         = new DivideByZeroException();

        runner.AfterTestMethodStarting_Callback = aggregator => aggregator.Add(ex);

        await runner.RunAsync();

        Assert.Same(ex, runner.RunTestCaseAsync_AggregatorResult);
        Assert.Empty(messageBus.Messages.OfType <ITestMethodCleanupFailure>());
    }
Пример #9
0
    public static async void FailureInBeforeTestMethodFinished_ReportsCleanupFailure_DoesNotIncludeExceptionsFromAfterTestMethodStarting()
    {
        var messageBus        = new SpyMessageBus();
        var testCases         = new[] { Mocks.TestCase <TestAssemblyRunnerTests.RunAsync>("Messages") };
        var runner            = TestableTestMethodRunner.Create(messageBus, testCases);
        var startingException = new DivideByZeroException();
        var finishedException = new InvalidOperationException();

        runner.AfterTestMethodStarting_Callback  = aggregator => aggregator.Add(startingException);
        runner.BeforeTestMethodFinished_Callback = aggregator => aggregator.Add(finishedException);

        await runner.RunAsync();

        var cleanupFailure = Assert.Single(messageBus.Messages.OfType <_TestMethodCleanupFailure>());

        Assert.Equal(typeof(InvalidOperationException).FullName, cleanupFailure.ExceptionTypes.Single());
    }