问题描述
是否有人在运行xUnit测试时知道如何向输出控制台添加其他信息?
Does anyone know how to add additional info to the output console when running xUnit tests?
我正在使用testdriven.net,但我不认为这就是我的答案所在.
I'm using testdriven.net, but I don't think that is where my answer lies.
我正在使用IUseFixture
(实际上是2.0的IClassFixture
)来维护两次测试之间的数据.当测试失败时,我想输出一些上下文数据以及失败和通常会得到的堆栈跟踪.
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?
推荐答案
您可以使用ITestOutputHelper将任何输出写入测试结果视图.只需让xUnit将其注入到您的构造函数中即可.
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!");
}
}
}
这篇关于xunit将信息添加到输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!