I just started testing xUnit.net, but it doesn't seem to capture any output (Console, Debug, Trace), as I would have expected.
Is that possible? I am using a sample .NET 4.0 class-library with xUnit.net 1.8.
xUnit.Net is an open source unit testing tool for the . Net Framework that provides an easy way to work with data driven unit tests.
Sometimes, you want to write tests and ensure they run against several target application platforms. The xUnit.net test runner that we've been using supports . NET Core 1.0 or later, . NET 5.0 or later, and .
In the tools folder of the console runner package folder, you will find xunit. console.exe .
The situation has changed a little with xUnit.net 2. I know the question is about an earlier version, but as people will land here having performed the upgrade, I thought it was worth pointing this out.
In order to see some kind of output in the test output in version 2 you will need to take a dependency in your test class (via a constructor argument) on an instance of Xunit.Abstractions.ITestOutputHelper
, then use the WriteLine
method on this interface. E.g.:
public class MyTestSpec { private readonly ITestOutputHelper _testOutputHelper; public MyTestSpec(ITestOutputHelper testOutputHelper) { _testOutputHelper = testOutputHelper; } [Fact] public void MyFact() { _testOutputHelper.WriteLine("Hello world"); } }
You could choose to hook up your logging framework to this interface, perhaps by injecting an ILog
implementation that forwarded all calls to ITestOutpuHelper
.
I acknowledge that you won't want to do this by default, but for diagnostic purposes from time to time it can be quite useful. This is especially true where your tests only fail on some cloud based build & test server!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With