Does anyone know how to add additional info to the output console when running xUnit tests?
I'm using testdriven.net, but I don't think that is where my answer lies.
I am using a IUseFixture
(actually IClassFixture
from 2.0) to maintain data between tests. When a test fails I want to output some of that contextual data along with the failure and the stack trace that you usually get.
Does anyone know of a hook I can use?
xUnit uses the [Fact] attribute to denote a parameterless unit test, which tests invariants in your code. In contrast, the [Theory] attribute denotes a parameterised test that is true for a subset of data. That data can be supplied in a number of ways, but the most common is with an [InlineData] attribute.
MSTest is concerned, the biggest difference between xUnit and the other two test frameworks (NUnit and MSTest) is that xUnit is much more extensible when compared to NUnit and MSTest.
One way to do it: add " --logger=trx" to the "dotnet test" command and then use the build step "Process xUnit test result report" from the "xUnit plugin". Use the option "MSTest-Version N/A (default) Pattern" and set pattern to "*/. trx". This is the answer!
It is common for unit test classes to share setup and cleanup code (often called "test context"). xUnit.net offers several methods for sharing this setup and cleanup code, depending on the scope of things to be shared, as well as the expense associated with the setup and cleanup code.
You can use ITestOutputHelper to write any output to the test result view. Just let xUnit inject it into your constructor.
using Xunit;
using Xunit.Abstractions;
namespace xUnitTestOutput
{
public class OutputTests
{
private readonly ITestOutputHelper _output;
public OutputTests(ITestOutputHelper output)
{
_output = output;
}
[Fact]
public void FirstOutputTest()
{
_output.WriteLine("This is output from the test!");
}
}
}
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