gpt4 book ai didi

c# - 使用 IClassFixture 时输出测试结果 XUnit .net core

转载 作者:太空宇宙 更新时间:2023-11-03 12:13:45 25 4
gpt4 key购买 nike

我一直使用 Nunit,现在转向 XUnit。

当我没有实现 IClassFixture 时,我成功地使用了 ITestOutputHelper,例如:

public myClassTest(ITestOutputHelper outputHelper)
{
this.outputHelper = outputHelper;
}

然而,当我实现 IClassFixture 时,我找不到注入(inject) 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;
}
}

作为 ITestOutputHelper,所有声明的类和共享装置都可以通过这种方式提供。

在输出窗口 (Ctrl-Alt-O)测试面板中,您得到了什么消息?

关于c# - 使用 IClassFixture 时输出测试结果 XUnit .net core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50780626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com