xUnit v2 IUseFixture<> 的替代方案

12

我正在尝试升级到 xUnit 2 beta(主要是因为更好的测试发现),但遇到了 IUseFixture<> 问题:

public abstract class TestCaseBase : IUseFixture<SelfHostFixture> 
{ /*common stuff here*/ }

public class Controller1Test : TestCaseBase {}

public class Controller2Test : TestCaseBase {}

我发现新的IClassFixture<>几乎符合我的要求,除了这个 fixture 会为每个派生类(Controller1Test, Controller2Test) 分别创建和销毁,而不是只创建和销毁一次。嗯,我可以把 IClassFixture<SelfHostFixture> 声明从基类移到每个测试类,但为什么要多次设置/销毁服务器?ICollectionFixture<> 对我没有用(fixture 的构造函数从未被调用)。
基本上,我想要的是:
  1. "Per run" fixture (必须在每次测试运行时只实例化一次)
  2. 启用并行运行,因为我的测试只是无状态的 HTTP 调用(我认为 ICollectionFixture<> 根本不能工作,因为同一集合内的测试不能并行运行,对吗?)
我错过了什么?

以防你还没有查看,我建议你查看Github上的类似问题和/或各种IXXXFixture和ctor arg机制的文档,以找到正确的管理方式。 - Ruben Bartelink
这似乎是相关的:http://xunit.codeplex.com/workitem/9748 - Tim Lovell-Smith
这是我使用的beta版本出现的问题,在2.0版本中已经修复了。 - UserControl
1个回答

7

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接