我按照文档中的示例进行了重现,但是当我运行测试时,它立即失败并显示:
以下构造函数参数没有匹配的夹具数据: IntegrationTestFixture fixture
这似乎无论我是使用 xUnit Facts 还是 Theories,或者使用哪个测试运行器都会发生。
夹具:
public class IntegrationTestFixture : IDisposable
{
public IntegrationTestFixture()
{
// (setup code)
this.GeneratedTestName = [randomly generated];
}
public void Dispose()
{
// (teardown code)
}
public string GeneratedTestName { get; private set; }
}
收藏品定义:
[CollectionDefinition("Live tests")]
public class IntegrationTestCollection : ICollectionFixture<IntegrationTestFixture>
{
// Intentionally left blank.
// This class only serves as an anchor for CollectionDefinition.
}
测试:
[CollectionDefinition("Live tests")]
public class SomeTests
{
private readonly IntegrationTestFixture fixture;
public SomeTests(IntegrationTestFixture fixture)
{
this.fixture = fixture;
}
[Fact]
public void MyTestMethod()
{
// ... test here
}
}