Reputation: 437
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)]
Reference Set maximum parallel threads
I have installed xunit-2.0.0-beta4-build2738(Prerelease). Also installed Xunit runner to find tests.
From my knowledge and research tells that Xunit does not run tests in the same collection in parallel. Reference Using test collections in xUnit.net v2 that is why for both the classes below I have used different collections.
Visual Studio 2013 finds my tests but when I run all the tests, it still runs tests serially. I want them to run in parallel.
If someone could help that would be great!
My code 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 references
How to run Selenium tests in parallel with xUnit
XUnit.net attributes
XUnit.net issues
Upvotes: 8
Views: 4430
Reputation: 3924
In xUnit, Each test class is a unique test collection. Tests within the same test class will not run in parallel against each other.
So in order to achieve that, you need to keep your tests in different collection(which you want to run in parallel), however that is not efficient way to solve your issue.
I answered this as per my knowledge and the content which I got on Internet, you can also refer to this link
Upvotes: 1
Reputation: 1370
It seems that Visual Studio doesn't support running tests in parallel. I haven't tested with the exact versions you asked about, but have found other comments saying as much. As suggested, running from the command line should work.
For me, I'm 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:
Upvotes: 0