使用 Visual Studio 测试运行器运行的 xUnit 测试的输出未显示在“输出"窗口中 [英] Output from xUnit tests run with Visual Studio test runner not shown in Output window
问题描述
我创建了一个名为 FooBarBaz
的全新 .NET Core 类库项目.然后我使用包管理器控制台运行:
安装包 xunit xunit
安装包 xunit xunit.runners.visualstudio
这是我添加的唯一代码:
使用Xunit;使用 Xunit.Abstractions;命名空间 FooBarBaz{公开课 Class1{私有只读 ITestOutputHelper 输出;public Class1(ITestOutputHelper 输出){this.output = 输出;output.WriteLine("从我的构造函数输出");}[事实]public void SmokeTest(){output.WriteLine("从我的测试中输出");断言.真(真);}}}
这直接基于
如何配置 xUnit 以在输出窗口中提供输出?
在输入问题并摆弄更多之后,出现了完全晦涩的解决方案:只测试那些失败strong> 在输出窗口中显示 ITestOutputHelper
输出.
尝试将断言更改为 Assert.True(false);
,您将得到:
不确定为什么这是默认设置,或者您将如何更改它.
I created a fresh .NET Core Class Library project named FooBarBaz
. I've then used the package manager console to run:
Install-Package xunit xunit
Install-Package xunit xunit.runners.visualstudio
This is the only code I have added:
using Xunit;
using Xunit.Abstractions;
namespace FooBarBaz
{
public class Class1
{
private readonly ITestOutputHelper output;
public Class1(ITestOutputHelper output)
{
this.output = output;
output.WriteLine("OUTPUT FROM MY CONSTRUCTOR");
}
[Fact]
public void SmokeTest()
{
output.WriteLine("OUTPUT FROM MY TEST");
Assert.True(true);
}
}
}
This is based straight on the xUnit.net documentation example. I know that the documentation goes on to talk about "Message Sinks" and whatnot, but I could've sworn I saw the message in the Output window of visual studio. In my real project this seems to work only erratically.
I know I can click the "Output" hyperlink after selecting a test and see it, but that's just one step extra, and that output doesn't have a monospace font either (which I'd like to have).
See this:
How do I configure xUnit to provide output in the Output window?
After typing the question and fiddling around some more, the completely obscure solution popped up: only tests that fail show ITestOutputHelper
output in the Output window.
Try changing the assertion to Assert.True(false);
and you'll get this:
Not sure why that's the default, or how you'd change it.
这篇关于使用 Visual Studio 测试运行器运行的 xUnit 测试的输出未显示在“输出"窗口中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!