I recently started using XUnit. I’m still discovering what is possible using this unit test framework.
One of the things I had to discover was how to write log messages during my tests. I could fall back to using Trace.WriteLine or Console.WriteLine but that is not the best solution. XUnit allows you to capture test output using a special interface called
Now if you call the ITestOutputHelper.WriteLine method, the output is captured and available inside your test output:
One of the things I had to discover was how to write log messages during my tests. I could fall back to using Trace.WriteLine or Console.WriteLine but that is not the best solution. XUnit allows you to capture test output using a special interface called
ITestOutputHelper
. In order to use this, just add a constructor argument for this interface and store it inside a variable inside your test class:Now if you call the ITestOutputHelper.WriteLine method, the output is captured and available inside your test output: