xUnit tests in parallel and sequential
Published in
1 min readOct 10, 2018
In this quick blog, I’ll explain how you can run your xUnit tests in parallel and sequential.
Each test class is a unique test collection and tests under it will run in sequence, so if you put all of your tests in the same collection then it will run sequentially.
In xUnit you can make following changes to achieve this:
Following will run in parallel:
namespace IntegrationTests
{
public class Class1
{
[Fact]
public void Test1()
{
Console.WriteLine("Test1 called");
} [Fact]
public void Test2()
{
Console.WriteLine("Test2 called");
}
} public class Class2
{
[Fact]
public void Test3()
{
Console.WriteLine("Test3 called");
} [Fact]
public void Test4()
{
Console.WriteLine("Test4 called");
}
}
}
To make it sequential you just need to put both the test classes under the same collection:
namespace IntegrationTests
{
[Collection("Sequential")]
public class Class1
{
[Fact]
public void Test1()
{
Console.WriteLine("Test1 called");
} [Fact]
public void Test2()
{
Console.WriteLine("Test2 called");
}
} [Collection("Sequential")]
public class Class2
{
[Fact]
public void Test3()
{
Console.WriteLine("Test3 called");
} [Fact]
public void Test4()
{
Console.WriteLine("Test4 called");
}
}
}