Example #1
0
        public void DiscovererWhichThrowsReturnsASingleFailedTest()
        {
            var testCase = TestableXunitTheoryTestCase.Create(typeof(ClassUnderTest), "TestWithThrowingData");
            var spy = new SpyMessageSink<ITestCaseFinished>();

            testCase.Run(spy);
            spy.Finished.WaitOne();

            var resultMessages = spy.Messages.OfType<ITestResultMessage>();
            var failed = (ITestFailed)Assert.Single(resultMessages);
            Assert.Equal("XunitTheoryTestCaseTests+Run+ClassUnderTest.TestWithThrowingData", failed.TestDisplayName);
            Assert.Equal("System.DivideByZeroException : Attempted to divide by zero.", failed.Message);
            Assert.Contains("XunitTheoryTestCaseTests.Run.ClassUnderTest.get_ThrowingData()", failed.StackTrace);
        }
Example #2
0
        public void EnumeratesDataAtRuntimeAndExecutesOneTestForEachDataRow()
        {
            var testCase = TestableXunitTheoryTestCase.Create(typeof(ClassUnderTest), "TestWithData");
            var spy = new SpyMessageSink<ITestCaseFinished>();

            testCase.Run(spy);
            spy.Finished.WaitOne();

            var resultMessages = spy.Messages.OfType<ITestResultMessage>();
            Assert.Equal(2, resultMessages.Count());
            var passed = (ITestPassed)Assert.Single(resultMessages, msg => msg is ITestPassed);
            Assert.Equal("XunitTheoryTestCaseTests+Run+ClassUnderTest.TestWithData(x: 42, y: 21.12, z: \"Hello\")", passed.TestDisplayName);
            var failed = (ITestFailed)Assert.Single(resultMessages, msg => msg is ITestFailed);
            Assert.Equal("XunitTheoryTestCaseTests+Run+ClassUnderTest.TestWithData(x: 0, y: 0, z: \"World!\")", failed.TestDisplayName);
        }
Example #3
0
        public void IssuesTestCaseMessagesAndCallsRunTests()
        {
            var testCase = TestableXunitTestCase.Create();
            var sink = new SpyMessageSink<ITestCaseFinished>();

            testCase.Run(sink);
            sink.Finished.WaitOne();

            Assert.Collection(sink.Messages,
                message =>
                {
                    var testCaseStarting = Assert.IsAssignableFrom<ITestCaseStarting>(message);
                    Assert.Same(testCase, testCaseStarting.TestCase);
                },
                message => Assert.IsType<SpyMessage>(message),
                message =>
                {
                    var testCaseFinished = Assert.IsAssignableFrom<ITestCaseFinished>(message);
                    Assert.Same(testCase, testCaseFinished.TestCase);
                    Assert.Equal(0, testCaseFinished.TestsRun);
                    Assert.Equal(0, testCaseFinished.TestsFailed);
                    Assert.Equal(0, testCaseFinished.TestsSkipped);
                    Assert.Equal(0M, testCaseFinished.ExecutionTime);
                }
            );
        }
Example #4
0
        public void CountsTestsSkipped()
        {
            var testCase = TestableXunitTestCase.Create(msgSink =>
            {
                msgSink.OnMessage(new TestSkipped());
                msgSink.OnMessage(new TestSkipped());
            });
            var sink = new SpyMessageSink<ITestCaseFinished>();

            testCase.Run(sink);
            sink.Finished.WaitOne();

            var testCaseFinished = Assert.IsAssignableFrom<ITestCaseFinished>(sink.Messages.Last());
            Assert.Equal(2, testCaseFinished.TestsSkipped);
        }
Example #5
0
        public void CountsTestResultMessages()
        {
            var testCase = TestableXunitTestCase.Create(msgSink =>
            {
                msgSink.OnMessage(Substitute.For<ITestResultMessage>());
                msgSink.OnMessage(Substitute.For<ITestPassed>());
                msgSink.OnMessage(Substitute.For<ITestFailed>());
                msgSink.OnMessage(Substitute.For<ITestSkipped>());
            });
            var sink = new SpyMessageSink<ITestCaseFinished>();

            testCase.Run(sink);
            sink.Finished.WaitOne();

            var testCaseFinished = Assert.IsAssignableFrom<ITestCaseFinished>(sink.Messages.Last());
            Assert.Equal(4, testCaseFinished.TestsRun);
        }
Example #6
0
        public void AggregatesTestRunTime()
        {
            var testCase = TestableXunitTestCase.Create(msgSink =>
            {
                msgSink.OnMessage(new TestPassed { ExecutionTime = 1.2M });
                msgSink.OnMessage(new TestFailed { ExecutionTime = 2.3M });
            });
            var sink = new SpyMessageSink<ITestCaseFinished>();

            testCase.Run(sink);
            sink.Finished.WaitOne();

            var testCaseFinished = Assert.IsAssignableFrom<ITestCaseFinished>(sink.Messages.Last());
            Assert.Equal(3.5M, testCaseFinished.ExecutionTime);
        }