JetBrains Rider 2019.1 Help

Code Inspection: Console output in Xunit tests

Output of unit tests is often printed using Console.WriteLine. However, this may not work correctly with 2.x, because parallelization is turned on by default there. Instead, as the documentation suggests, you should use ITestOutputHelper to capture test output.

JetBrains Rider will warn you about usages of Console.WriteLine inside Fact methods and suggest a quick-fix that will convert these usages to instances of ITestOutputHelper.

Suboptimal code

After the quick-fix

public class XUnitTestClass { [Fact] public void Test1() { Console.WriteLine("Hello"); } }
public class XUnitTestClass { private readonly ITestOutputHelper _testOutputHelper; public XUnitTestClass(ITestOutputHelper testOutputHelper) { _testOutputHelper = testOutputHelper; } [Fact] public void Test1() { _testOutputHelper.WriteLine("Hello"); } }
Last modified: 11 June 2019

See Also