[英]XUnit.net: run Theories in parallel
xunit.net supports parallel test execution. xunit.net支持并行测试执行。
My tests are parameterized (theories). 我的测试已参数化(理论)。 Every test I run against different storage.
我在不同的存储上运行的每个测试。 Here's an example:
这是一个例子:
public class TestCase1
{
[Theory]
[InlineData("mssql")]
[InlineData("oracle")]
[InlineData("pgsql")]
[InlineData("sqlite")]
public void DoTests(string storage) {}
}
public class TestCase2
{
[Theory]
[InlineData("mssql")]
[InlineData("oracle")]
[InlineData("pgsql")]
[InlineData("sqlite")]
public void DoTests(string storage) {}
}
By default all tests are executed in parallel . 默认情况下,所有测试都是并行执行的 。 By they can be grouped in Collections (with help of
Collection
attribute). 通过它们可以在集合中分组(借助“
Collection
属性)。
I can't run all tests in parallel as every test case has it own db schema. 我不能并行运行所有测试,因为每个测试用例都有自己的数据库模式。 So I put all tests into a single collection with assembly-level attribute:
因此,我将所有测试放入具有程序集级属性的单个集合中:
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)]
But it also means that tests for differnt storages are also run serially. 但这也意味着针对不同存储的测试也将顺序运行。
What I want is to run tests for different storages in parallel but for single storage in serial: 我想要的是针对不同的存储并行运行测试,但针对串行的单个存储运行测试:
=> TestCase1.DoTest("mssql") => TestCase2.DoTest("mssql") => TestCase1.DoTest(“ mssql”)=> TestCase2.DoTest(“ mssql”)
=> TestCase1.DoTest("oracle") => TestCase2.DoTest("oracle") => TestCase1.DoTest(“ oracle”)=> TestCase2.DoTest(“ oracle”)
and so on 等等
Is it possible in xunit.net? 在xunit.net中可以吗?
UPDATE: (put it here as SO doesn't support code in comments). 更新:(将其放在此处,因为SO不支持注释中的代码)。 As @BradWilson suggested, it's possible to split tests with derived classes:
正如@BradWilson所建议的,可以使用派生类拆分测试:
public class TestCase1
{
public void DoTests(string storage) {}
}
public class TestCase1_MSSQL
{
[Fact]
public void DoTests(string storage)
{
DoTests("mssql");
}
}
public class TestCase1_Oracle
{
[Fact]
public void DoTests(string storage)
{
DoTests("oracle");
}
}
I wouldn't do this with theories and inline data; 我不会用理论和内联数据来做到这一点; instead, I would do it with an abstract base class and concrete test classes for each storage method.
相反,我将使用每种存储方法的抽象基类和具体测试类来实现。 That gets you the grouping you want.
这可以为您提供所需的分组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.