コード例 #1
0
ファイル: ResultVisitorTests.cs プロジェクト: zahafyou/xunit
        public static void ConvertsITestFailed()
        {
            Exception ex;

            try
            {
                throw new Exception();
            }
            catch (Exception e)
            {
                ex = e;
            }

            TestResult testResult = null;
            var        listener   = Substitute.For <ITestListener>();

            listener.WhenAny(l => l.TestFinished(null))
            .Do <TestResult>(result => testResult = result);
            var visitor = new ResultSink(listener, 42);
            var message = Mocks.TestFailed(typeof(object), nameof(object.GetHashCode), "Display Name", executionTime: 123.45M, ex: ex);

            visitor.OnMessageWithTypes(message, null);

            Assert.NotNull(testResult);
            Assert.Same(typeof(object), testResult.FixtureType);
            Assert.Equal(nameof(object.GetHashCode), testResult.Method.Name);
            Assert.Equal("Display Name", testResult.Name);
            Assert.Equal(TestState.Failed, testResult.State);
            Assert.Equal(123.45, testResult.TimeSpan.TotalMilliseconds);
            Assert.Equal(42, testResult.TotalTests);
            Assert.Equal("System.Exception : " + ex.Message, testResult.Message);
            Assert.Equal(ex.StackTrace, testResult.StackTrace);
        }
コード例 #2
0
ファイル: ResultVisitorTests.cs プロジェクト: zahafyou/xunit
    public static void SignalsFinishedEventUponReceiptOfITestAssemblyFinished()
    {
        var listener = Substitute.For <ITestListener>();
        var visitor  = new ResultSink(listener, 42);
        var message  = Substitute.For <ITestAssemblyFinished>();

        visitor.OnMessageWithTypes(message, null);

        Assert.True(visitor.Finished.WaitOne(0));
    }
コード例 #3
0
ファイル: ResultVisitorTests.cs プロジェクト: zahafyou/xunit
        public static void Skip_StaysInCurrentState(TestRunState initialState)
        {
            var listener = Substitute.For <ITestListener>();
            var visitor  = new ResultSink(listener, 42)
            {
                TestRunState = initialState
            };

            visitor.OnMessageWithTypes(Substitute.For <ITestSkipped>(), null);

            Assert.Equal(initialState, visitor.TestRunState);
        }
コード例 #4
0
ファイル: ResultVisitorTests.cs プロジェクト: zahafyou/xunit
        public static void Skip_MovesToSuccess()
        {
            var listener = Substitute.For <ITestListener>();
            var visitor  = new ResultSink(listener, 42)
            {
                TestRunState = TestRunState.NoTests
            };

            visitor.OnMessageWithTypes(Substitute.For <ITestSkipped>(), null);

            Assert.Equal(TestRunState.Success, visitor.TestRunState);
        }
コード例 #5
0
ファイル: ResultVisitorTests.cs プロジェクト: zahafyou/xunit
        public static void FailureSetsStateToFailed(TestRunState initialState)
        {
            var listener = Substitute.For <ITestListener>();
            var visitor  = new ResultSink(listener, 42)
            {
                TestRunState = initialState
            };

            visitor.OnMessageWithTypes(Mocks.TestFailed(typeof(object), "GetHashCode"), null);

            Assert.Equal(TestRunState.Failure, visitor.TestRunState);
        }
コード例 #6
0
ファイル: ResultVisitorTests.cs プロジェクト: zahafyou/xunit
        public static void ConvertsITestPassed()
        {
            TestResult testResult = null;
            var        listener   = Substitute.For <ITestListener>();

            listener.WhenAny(l => l.TestFinished(null))
            .Do <TestResult>(result => testResult = result);
            var visitor = new ResultSink(listener, 42);
            var message = Mocks.TestPassed(typeof(object), nameof(object.GetHashCode), "Display Name", executionTime: 123.45M);

            visitor.OnMessageWithTypes(message, null);

            Assert.NotNull(testResult);
            Assert.Same(typeof(object), testResult.FixtureType);
            Assert.Equal(nameof(object.GetHashCode), testResult.Method.Name);
            Assert.Equal("Display Name", testResult.Name);
            Assert.Equal(TestState.Passed, testResult.State);
            Assert.Equal(123.45, testResult.TimeSpan.TotalMilliseconds);
            Assert.Equal(42, testResult.TotalTests);
        }
コード例 #7
0
ファイル: ResultVisitorTests.cs プロジェクト: zahafyou/xunit
        public static void LogsTestFailure(IMessageSinkMessage message, string messageType)
        {
            var listener = Substitute.For <ITestListener>();

            using (var visitor = new ResultSink(listener, 42)
            {
                TestRunState = TestRunState.NoTests
            })
            {
                visitor.OnMessageWithTypes(message, null);

                Assert.Equal(TestRunState.Failure, visitor.TestRunState);
                var testResult = listener.Captured(x => x.TestFinished(null)).Arg <TestResult>();
                Assert.Equal($"*** {messageType} ***", testResult.Name);
                Assert.Equal(TestState.Failed, testResult.State);
                Assert.Equal(1, testResult.TotalTests);
                Assert.Equal("ExceptionType : This is my message \t\r\n", testResult.Message);
                Assert.Equal("Line 1\r\nLine 2\r\nLine 3", testResult.StackTrace);
            }
        }
コード例 #8
0
        public static void ConvertsITestSkipped()
        {
            TestResult testResult = null;
            var        listener   = Substitute.For <ITestListener>();

            listener.WhenAny(l => l.TestFinished(null))
            .Do <TestResult>(result => testResult = result);
            var visitor = new ResultSink(listener, 42);
            var message = Mocks.TestSkipped(typeof(string), "Contains", "Display Name", executionTime: 123.45M, skipReason: "I forgot how to run");

            visitor.OnMessageWithTypes(message, null);

            Assert.NotNull(testResult);
            Assert.Same(typeof(string), testResult.FixtureType);
            Assert.Equal("Contains", testResult.Method.Name);
            Assert.Equal("Display Name", testResult.Name);
            Assert.Equal(TestState.Ignored, testResult.State);
            Assert.Equal(123.45, testResult.TimeSpan.TotalMilliseconds);
            Assert.Equal(42, testResult.TotalTests);
            Assert.Equal("I forgot how to run", testResult.Message);
        }