Controlling the Serial and Parallel Test on XUnit
My Project requires both Serial and Parallel test execution on a project. I’d like to know how to handle this situation.
Collection
A collection is the unit of tests. The tests that are in the same collection, it runs serially. By default, it is per class.
Run Parallel
If you want to run tests parallel, you need to split the class. In this case, ParallelTest01 and ParallelTest02 run parallelly. However, Test1() and Test2() run serially.
Run Serially for more than two classes
You can use Collection
annotation. It tells both classes are in the same collection. It runs as if it is in the same class. That means serial. In this case, Test7() and Test8() runs Serially.
Run Serially exclusively
However, in some use cases, we want to run parallel and serial in the same project. Even if you use Collection
, it runs parallelly as the different classes that mean Collections. I want to run almost all tests in parallel but for some test, it should run serially exclusively. You can use DisableParallelization = true
option with CollectionDefinition
Annotation. This option enables us that Parallel-capable test collections will be run first (in parallel), followed by parallel-disabled test collections (run sequentially).
SerialTest class will be executed after finishing any other tests.
Source code
For more information, you can refer to this page.