Can't run tests with XUnit in parallel in Visual Studio
I have two classes TestClass1, TestClass2
I have set MaxParallel threads through assembly in AssemblyInfo.cs file in my test project:
[assembly: Xunit.CollectionBehaviorAttribute (MaxParallelThreads = 4)]
Link Set Max Parallel Threads
I have installed xunit-2.0.0-beta4-build2738 (Prerelease). Also installed Xunit runner to find tests.
From my knowledge and research, it is reported that Xunit does not run tests on the same collection in parallel. Link Using Test Collections in xUnit.net v2 , so I used different collections for both classes below.
Visual Studio 2013 finds my tests, but when I run all the tests, it still runs the tests one at a time. I want them to run in parallel.
If anyone can help, that would be great!
My code is below:
Namespace1
namespace name1
{
public class MFixture
{
}
[CollectionDefinition("Test1")]
public class CollectionClass : ICollectionFixture<MFixture>
{
}
[Collection("Test1")]
public class TestClass1
{
// variables
public TestClass1()
{
//code
}
[Fact]
public void method1()
{
//code
}
[Fact]
public void method2()
{
//code
}
}
}
Namespace2
namespace name2
{
public class MFixture1
{
}
[CollectionDefinition("Test2")]
public class CollectionClass1 : ICollectionFixture<MFixture1>
{
}
[Collection("Test2")]
public class TestClass2
{
// variables
public TestClass2()
{
//code
}
[Fact]
public void method12()
{
//code
}
[Fact]
public void method22(){
{
//code
}
}
}
Other links
How to run Selenium tests in parallel with xUnit
XUnit.net attributes XUnit.net
problems
source to share
It seems that Visual Studio doesn't support running tests in parallel. I have not tested with the exact versions you asked for, but found other comments saying the same. As suggested , command line work should work.
For me, I am using VS2015, dnx 1.0.0-rc1-final, xunit 2.1.0, xunit.runner.dnx 2.1.0-rc1-build204 and can confirm that VS Test Explorer is dumb.
According to the docs :
By default, each test class is a unique test collection.
So given some contrived "tests" like these, it should be easy to see if they run in parallel or not:
Visual Studio:
Command line:
source to share
In xUnit, Each test class is a unique test collection. Tests within the same class of tests will not run in parallel to each other.
So, to achieve this, you need to keep your tests in a different collection (which you want to run in parallel), however this is not an efficient way to solve your problem.
I answered this according to my knowledge and content I got online, you can also refer to this link
source to share