在使用xunit for .NET 1.0 framework net46时,我不断收到此错误.
The following constructor parameters did not have matching fixture data
Run Code Online (Sandbox Code Playgroud)
我看过这篇文章:Collection fixture不会注入并按照这里描述的关于收集夹具的说明:
http://xunit.github.io/docs/shared-context.html#collection-fixture
似乎没什么用.
有什么可能导致这个的建议吗?
Jer*_*vel 11
另一个可能失败的情况是,如果[CollectionDefinition]是在执行测试程序集之外的类型上定义的。属性本身需要在其中定义,否则 xUnit 将不会选择它。
Nik*_*hou 10
在我的情况下,根据指示,事实证明这是正确的.我错误地注释了这个课程
[Collection("ProjectCollection")]
Run Code Online (Sandbox Code Playgroud)
代替:
[Collection("ActorProjectCollection")]
Run Code Online (Sandbox Code Playgroud)
我必须说,如果错误消息给出了更明确的错误提示,那么XUnit的依赖注入机制将会大大改进.
当您的夹具类的构造函数由于其他问题而失败时,可能会出现此异常,在我的情况下,连接到本地 Mongo 服务器。
要么寻找其他故障并首先解决这些故障,要么减轻您的构造函数以使其减少。
小智 5
就我而言,我必须在测试类上实现 IClassFixture<> 接口。
public class MyTests : IClassFixture<QueryTestFixture>
Run Code Online (Sandbox Code Playgroud)
将 QueryTestFixture 移动到另一个项目后,Class 属性停止工作
[Collection("QueryCollection")]
Run Code Online (Sandbox Code Playgroud)
这与夹具类中的实现相关联(见下文)
[CollectionDefinition("QueryCollection")]
public class QueryCollection : ICollectionFixture<QueryTestFixture> { }
Run Code Online (Sandbox Code Playgroud)
我尝试了许多替代方法来解决这个问题,但最终阅读了 xunit.net 关于共享上下文的解释。这提供了一个解决方案。