Reputation: 9500
xunit.net supports parallel test execution.
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).
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("oracle") => TestCase2.DoTest("oracle")
and so on
Is it possible in xunit.net?
UPDATE: (put it here as SO doesn't support code in comments). As @BradWilson suggested, it's possible to split tests with derived classes:
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");
}
}
Upvotes: 1
Views: 1162
Reputation: 70736
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.
Upvotes: 2