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

后端 未结 7 1164
误落风尘
误落风尘 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:53

    If you used xUnit.net 1.x, you may have previously been writing output to Console, Debug, or Trace. When xUnit.net v2 shipped with parallelization turned on by default, this output capture mechanism was no longer appropriate; it is impossible to know which of the many tests that could be running in parallel were responsible for writing to those shared resources. Users who are porting code from v1.x to v2.x should use one of the two new methods instead.

    Have a look here for example of how to perform logging with xUnit.net v2:

    http://xunit.github.io/docs/capturing-output.html

    This is the example:

    using Xunit;
    using Xunit.Abstractions;
    
    public class MyTestClass
    {
        private readonly ITestOutputHelper output;
    
        public MyTestClass(ITestOutputHelper output)
        {
            this.output = output;
        }
    
        [Fact]
        public void MyTest()
        {
            var temp = "my class!";
            output.WriteLine("This is output from {0}", temp);
        }
    }
    

提交回复
热议问题