Example #1
0
        public async void LongRunningTest_Once_WithoutLongRunningTestHandler()
        {
            var events   = new List <IDiagnosticMessage>();
            var diagSink = Substitute.For <IMessageSinkWithTypes>();

            diagSink.WhenForAnyArgs(x => x.OnMessageWithTypes(null, null))
            .Do(callInfo =>
            {
                var message           = callInfo.Arg <IMessageSinkMessage>();
                var diagnosticMessage = message as IDiagnosticMessage;
                if (diagnosticMessage != null)
                {
                    events.Add(diagnosticMessage);
                }
            });
            var sink     = new TestableTestExecutionSink(diagnosticMessageSink: diagSink, longRunningSeconds: 1);
            var testCase = Substitute.For <ITestCase>();

            testCase.DisplayName.Returns("My test display name");

            sink.OnMessage(Substitute.For <ITestAssemblyStarting>());
            sink.OnMessage(new TestCaseStarting(testCase));
            await sink.AdvanceClockAsync(1000);

            sink.OnMessage(new TestCaseFinished(testCase, 8009, 1, 0, 0));
            sink.OnMessage(Substitute.For <ITestAssemblyFinished>());

            var @event = Assert.Single(events);

            Assert.Equal("[Long Running Test] 'My test display name', Elapsed: 00:00:01", @event.Message);
        }
Example #2
0
        public async void ShortRunningTests_NoMessages()
        {
            var sink   = new TestableTestExecutionSink(longRunningSeconds: 1);
            var events = new List <ILongRunningTestsMessage>();

            sink.LongRunningTestsEvent += args => events.Add(args.Message);
            var testCase1 = Substitute.For <ITestCase>();

            sink.OnMessage(Substitute.For <ITestAssemblyStarting>());
            sink.OnMessage(new TestCaseStarting(testCase1));
            await sink.AdvanceClockAsync(100);

            sink.OnMessage(new TestCaseFinished(testCase1, 8009, 1, 0, 0));
            sink.OnMessage(Substitute.For <ITestAssemblyFinished>());

            Assert.Empty(events);
        }
Example #3
0
        public async void OnlyIncludesLongRunningTests()
        {
            var sink   = new TestableTestExecutionSink(longRunningSeconds: 1);
            var events = new List <ILongRunningTestsMessage>();

            sink.LongRunningTestsEvent += args => events.Add(args.Message);
            var testCase1 = Substitute.For <ITestCase>();
            var testCase2 = Substitute.For <ITestCase>();

            sink.OnMessage(Substitute.For <ITestAssemblyStarting>());
            sink.OnMessage(new TestCaseStarting(testCase1));
            await sink.AdvanceClockAsync(500);

            sink.OnMessage(new TestCaseStarting(testCase2));  // Started later, hasn't run long enough
            await sink.AdvanceClockAsync(500);

            sink.OnMessage(new TestCaseFinished(testCase1, 8009, 1, 0, 0));
            sink.OnMessage(new TestCaseFinished(testCase2, 8009, 1, 0, 0));
            sink.OnMessage(Substitute.For <ITestAssemblyFinished>());

            var @event = Assert.Single(events);

            Assert.Equal(TimeSpan.FromSeconds(1), @event.ConfiguredLongRunningTime);
            var receivedTestCasePair = Assert.Single(@event.TestCases);

            Assert.Same(testCase1, receivedTestCasePair.Key);
            Assert.Equal(TimeSpan.FromSeconds(1), receivedTestCasePair.Value);
        }
Example #4
0
        public async void LongRunningTest_Once_WithLongRunningTestHandler()
        {
            var sink   = new TestableTestExecutionSink(longRunningSeconds: 1);
            var events = new List <ILongRunningTestsMessage>();

            sink.LongRunningTestsEvent += args => events.Add(args.Message);
            var testCase = Substitute.For <ITestCase>();

            sink.OnMessage(Substitute.For <ITestAssemblyStarting>());
            sink.OnMessage(new TestCaseStarting(testCase));
            await sink.AdvanceClockAsync(1000);

            sink.OnMessage(new TestCaseFinished(testCase, 8009, 1, 0, 0));
            sink.OnMessage(Substitute.For <ITestAssemblyFinished>());

            var @event = Assert.Single(events);

            Assert.Equal(TimeSpan.FromSeconds(1), @event.ConfiguredLongRunningTime);
            var receivedTestCasePair = Assert.Single(@event.TestCases);

            Assert.Same(testCase, receivedTestCasePair.Key);
            Assert.Equal(TimeSpan.FromSeconds(1), receivedTestCasePair.Value);
        }
Example #5
0
        public void SetsExecutionSummary()
        {
            var assemblyFinished = Substitute.For <ITestAssemblyFinished>();

            assemblyFinished.TestsRun.Returns(2112);
            assemblyFinished.TestsFailed.Returns(42);
            assemblyFinished.TestsSkipped.Returns(6);
            assemblyFinished.ExecutionTime.Returns(123.4567M);

            var sink = new TestableTestExecutionSink();

            sink.OnMessage(assemblyFinished);

            Assert.Equal(2112, sink.ExecutionSummary.Total);
            Assert.Equal(42, sink.ExecutionSummary.Failed);
            Assert.Equal(6, sink.ExecutionSummary.Skipped);
            Assert.Equal(123.4567M, sink.ExecutionSummary.Time);
        }