c# - 使用 IClassFixture 时输出测试结果 XUnit .net core
问题描述
我一直使用 Nunit,现在转向 XUnit。
ITestOutputHelper
当我不实现时,我使用成功IClassFixture
,例如:
public myClassTest(ITestOutputHelper outputHelper)
{
this.outputHelper = outputHelper;
}
但是,当我实施时,我IClassFixture
找不到注入ITestOutputHelper
.
我无法实现 ITestOutputHelper 的示例
public class MyIntegrationTests : IClassFixture<TestServerFixture<Startup>>
{
public MyIntegrationTests (TestServerFixture<Startup> testServerFixture)
{
client = testServerFixture.Client;
}
}
我错过了显而易见的事情吗?
解决方案
它应该通过以下方式工作:
public class MyIntegrationTests : IClassFixture<TestServerFixture<Startup>>
{
public MyIntegrationTests (TestServerFixture<Startup> testServerFixture, ITestOutputHelper outputHelper)
{
client = testServerFixture.Client;
this.outputHelper = outputHelper;
}
}
as ITestOutputHelper
,并且所有声明的 Class 和 Shared 固定装置都可以通过这种方式提供。
在“输出”窗口(Ctrl-Alt-O)的“测试”面板中,您收到了什么消息?
推荐阅读
- java - JavaFX如何处理来自控制器类的ActionEvent?
- bash - 监视添加到目录的文件大小(Bash)
- c# - C#:分配自动属性时会发生什么?
- azure - 在 Azure AD 租户的 Azure 门户中将成员作为组所有者添加到组
- reporting-services - 在 SSRS 报告中将数字更改为分数
- javascript - 在 d3 中构建堆叠条形图时动态获取不同的颜色
- reporting-services - SSRS 中迷你图的条件格式/颜色
- c++ - C++ 将派生类的成员更改为其专用版本
- xml - xpath 索引文本节点
- android - 我可以在 Android Studio 上构建现有的 AOSP/Lineage OS 应用程序吗?