简体   繁体   中英

Cant run xunit tests in parallel when classes are inheriting some class

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM