首页 > 解决方案 > 使用 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;
    }
}

我错过了显而易见的事情吗?

标签: c#asp.net-core-webapixunit.net

解决方案


它应该通过以下方式工作:

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)的“测试”面板中,您收到了什么消息?


推荐阅读