Пример #1
0
        public void ShouldReportResultsToTestDrivenDotNet()
        {
            var testDriven = new StubTestListener();

            using (var console = new RedirectedConsole())
            {
                var listener = new TestDrivenListener(testDriven);

                var convention = SelfTestConvention.Build();
                convention.CaseExecution.Skip(x => x.Method.Has <SkipAttribute>(), x => x.Method.GetCustomAttribute <SkipAttribute>().Reason);
                convention.Parameters.Add <InputAttributeParameterSource>();

                typeof(PassFailTestClass).Run(listener, convention);

                var testClass = typeof(PassFailTestClass).FullName;

                console.Lines()
                .ShouldEqual(
                    "Console.Out: Fail",
                    "Console.Error: Fail",
                    "Console.Out: Pass",
                    "Console.Error: Pass");

                var results = testDriven.TestResults;
                results.Count.ShouldEqual(4);

                foreach (var result in results)
                {
                    result.FixtureType.ShouldEqual(null);
                    result.Method.ShouldEqual(null);
                    result.TimeSpan.ShouldEqual(TimeSpan.Zero);
                    result.TotalTests.ShouldEqual(0);
                    result.TestRunnerName.ShouldBeNull();
                }

                results[0].Name.ShouldEqual(testClass + ".SkipWithReason");
                results[0].State.ShouldEqual(TestState.Ignored);
                results[0].Message.ShouldEqual("Skipped with reason.");
                results[0].StackTrace.ShouldBeNull();

                results[1].Name.ShouldEqual(testClass + ".SkipWithoutReason");
                results[1].State.ShouldEqual(TestState.Ignored);
                results[1].Message.ShouldBeNull();
                results[1].StackTrace.ShouldBeNull();

                results[2].Name.ShouldEqual(testClass + ".Fail");
                results[2].State.ShouldEqual(TestState.Failed);
                results[2].Message.ShouldEqual("Fixie.Tests.FailureException");
                results[2].StackTrace.Lines().Select(CleanBrittleValues).ShouldEqual(
                    "'Fail' failed!",
                    "   at Fixie.Tests.TestDriven.TestDrivenListenerTests.PassFailTestClass.Fail() in " + PathToThisFile() + ":line #");

                results[3].Name.ShouldEqual(testClass + ".Pass(123)");
                results[3].State.ShouldEqual(TestState.Passed);
                results[3].Message.ShouldBeNull();
                results[3].StackTrace.ShouldBeNull();
            }
        }
Пример #2
0
        public void ShouldReportResultsToTestDrivenDotNet()
        {
            var testDriven = new StubTestListener();
            var listener   = new TestDrivenListener(testDriven);

            using (var console = new RedirectedConsole())
            {
                Run(listener);

                console.Lines()
                .ShouldBe(
                    "Console.Out: Fail",
                    "Console.Error: Fail",
                    "Console.Out: FailByAssertion",
                    "Console.Error: FailByAssertion",
                    "Console.Out: Pass",
                    "Console.Error: Pass");
            }

            var results = testDriven.TestResults;

            results.Count.ShouldBe(5);

            foreach (var result in results)
            {
                result.FixtureType.ShouldBe(null);
                result.Method.ShouldBe(null);
                result.TimeSpan.ShouldBe(TimeSpan.Zero);
                result.TotalTests.ShouldBe(0);
                result.TestRunnerName.ShouldBe(null);
            }

            var fail              = results[0];
            var failByAssertion   = results[1];
            var pass              = results[2];
            var skipWithReason    = results[3];
            var skipWithoutReason = results[4];

            skipWithReason.Name.ShouldBe(TestClass + ".SkipWithReason");
            skipWithReason.State.ShouldBe(TestState.Ignored);
            skipWithReason.Message.ShouldBe("⚠ Skipped with reason.");
            skipWithReason.StackTrace.ShouldBe(null);

            skipWithoutReason.Name.ShouldBe(TestClass + ".SkipWithoutReason");
            skipWithoutReason.State.ShouldBe(TestState.Ignored);
            skipWithoutReason.Message.ShouldBe(null);
            skipWithoutReason.StackTrace.ShouldBe(null);

            fail.Name.ShouldBe(TestClass + ".Fail");
            fail.State.ShouldBe(TestState.Failed);
            fail.Message.ShouldBe("Fixie.Tests.FailureException");
            fail.StackTrace
            .CleanStackTraceLineNumbers()
            .Lines()
            .ShouldBe(
                "'Fail' failed!",
                "",
                At("Fail()"));

            failByAssertion.Name.ShouldBe(TestClass + ".FailByAssertion");
            failByAssertion.State.ShouldBe(TestState.Failed);
            failByAssertion.Message.ShouldBe("Fixie.Tests.Assertions.AssertException");
            failByAssertion.StackTrace
            .CleanStackTraceLineNumbers()
            .Lines()
            .ShouldBe(
                "Expected: 2",
                "Actual:   1",
                "",
                At("FailByAssertion()"));

            pass.Name.ShouldBe(TestClass + ".Pass");
            pass.State.ShouldBe(TestState.Passed);
            pass.Message.ShouldBe(null);
            pass.StackTrace.ShouldBe(null);
        }