Using ReSharper, how to show debug output during a long-running unit test?

后端 未结 7 1073
误落风尘
误落风尘 2020-12-28 13:06

I\'m using xUnit with the ReSharper test runner and the xUnitContrib resharper plugin.

When I have a long-running test, I\'d like to be able to output some progress

7条回答
  •  隐瞒了意图╮
    2020-12-28 13:55

    XunitLogger uses AsyncLocal to keep track of the logging context so calls to Trace.Writeline and Console.Writeline can be routed to the correct instance of ITestOutputHelper.

    Usage:

    static class ClassBeingTested
    {
        public static void Method()
        {
            Trace.WriteLine("From Trace");
            Console.WriteLine("From Console");
            Console.Error.WriteLine("From Console Error");
        }
    }
    
    public class TestBaseSample  :
        XunitLoggingBase
    {
        [Fact]
        public void Write_lines()
        {
            WriteLine("From Test");
            ClassBeingTested.Method();
    
            var logs = XunitLogger.Logs;
    
            Assert.Contains("From Test", logs);
            Assert.Contains("From Trace", logs);
            Assert.Contains("From Console", logs);
            Assert.Contains("From Console Error", logs);
        }
    
        public TestBaseSample(ITestOutputHelper output) :
            base(output)
        {
        }
    }
    

提交回复
热议问题