0
votes

Can't run xunit tests in parallel

  1. Created 2 classes with a nonsense test which only sleeps and returns. Then inherited from an empty base class. The tests ran in parallel.

  2. Changed the 2 classes to inherit from a real base class I need to use, which contains methods and some constants, and the tests don't run in parallel anymore.

The base class I'm inheriting from does not contain any testing related code (all fact annotated functions are in the child classes).

I'm using xUnit 2.4.1 with C# and .Net 4.7.2

I suspect there is something in the base class which prohibits running in parallel, but don't understand what. I have several async methods there which utilize an auto-generated REST client.

1
Please post relavant code instead of trying to explain it.Sach
How are you determining whether the tests run in parallel?Scott Hannen
I know they run in parallel because there's an animation in Visual studio of both tests running, and the test completes after 5 seconds, when each has a 5 seconds sleep.Tylor Durden

1 Answers

0
votes

From documentation:

How does xUnit.net decide which tests can run against each other in parallel? It uses a concept called test collections to make that decision.

By default, each test class is a unique test collection. Tests within the same test class will not run in parallel against each other.

Different classes/types can be executed in parallel. Even if class derived of some base class, it is still considered as different class.

But tests executes by Visual Studio, and by default tests executes on single thread. Check, did you enabled Tests in Parallel feature in Visual Studio test explorer?

Just to be sure, I were able to execute tests of different classes, which derived of one base class in parallel, by running tests without Visual Studio.

Update

In case when test class derives class which include own test methods, then inherited methods will be run as part of current class and so will not be run in parallel with methods of current class.

But derived class tests methods will be executed as part of this specific class and will be run in parallel with other classes which derives from it.
In this case you should observe those methods to be executed twice, one as part of "base" class and part of derived class.