我正在使用xUnit 2.0 collection fixtures在多个不同的测试类之间共享通用数据库设置/拆卸。夹具还提供了一些帮助属性,所以我将它注入到每个测试类中。集合夹具不会注入
我重新创建示例中的文档,但是当我运行测试,它立即失败:
下面的构造函数的参数没有匹配的灯具数据:IntegrationTestFixture夹具
这无论我使用的是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
}
}