我有一个 xunit 测试模式:
[Collection("SomeFixture")]
public class SomeClass
{
public SomeClass(SomeFixture fixture) {}
public class MethodA: SomeClass
{
public MethodA(SomeFixture fixture): base(fixture) {}
// ...
}
public class MethodB: SomeClass
{
public MethodB(SomeFixture fixture): base(fixture) {}
// ...
}
}
注意,子类并不直接具有
属性;这是遗传的。[Collection("SomeFixture")]
今天,我将我的项目更新为
net8.0
,包括:
xunit
从 v 2.5.0 到 2.6.3xunit.runner.visualstudio
从 v 2.5.0 到 2.5.5在此更新后,我现在收到编译器错误:
Code: Error xUnit1041
Description: Fixture argument 'fixture' does not have a fixture source (if it comes from a collection definition, ensure the definition is in the same assembly as the test) (https://xunit.net/xunit.analyzers/rules/xUnit1041)
通过将
Collection
属性复制到每个子类可以轻松解决此问题。然而,我有数百个这样的测试来做到这一点。
有没有办法避免繁琐的复制/粘贴来解决这个问题?
解决方法是回滚到 xunit 2.6.2。