Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run unit tests (MSTest) in parallel?

I am looking for ways to run test suites in parallel.

I am aware of .testrunconfig setting. This allows you to multiplex on the number of CPUs.

I want to run 1000 tests in parallel. This makes sense because I am testing a web service, so 90% of the time spent in a test is waiting for the service to respond.

Any ideas on how to pull this off ? The tests are written for VS, but I am open to running them outside of VS.

Later edit: the Visual Studio test team have added this in VS 2015 Update 1. See Mark Sowul's answer bellow.

like image 394
Bogdan Gavril MSFT Avatar asked Oct 12 '10 16:10

Bogdan Gavril MSFT


People also ask

Does MSTest run tests in parallel?

The biggest advantage of MSTest is that it allows parallelization at the method level. As opposed to the other frameworks which only allow parallelization at the class level. So, for example, If you have 100 test methods in 5 classes, MSTest will let you run 100 tests in parallel.

How do you run test cases in parallel?

Parallel Testing using TestNG and Selenium Methods: Helps run methods in separate threads. Tests: Help to run all methods belonging to the same tag in the same thread. Classes: Helps to run all methods belonging to a class in a single thread. Instances: Helps run all methods in the same instance in the same thread.

Do unit tests run in parallel C#?

Unit tests run one at a time. There is no parallelism.

How do I run a MSTest unit test?

To run MSTest unit tests, specify the full path to the MSTest executable (mstest.exe) in the Unit Testing Options dialog. To call this dialog directly from the editor, right-click somewhere in the editor and then click Options.


1 Answers

Most of the answers on this page forget to mention that MSTest parallelizes tests in separate assemblies. You have to split your unittests into multiple .dll's to paralelize it.

But! The recent version - MSTest V2 - now CAN parallelize "in-assembly" (yay!) you just need to install a couple of nuget packages in your test project - TestFramework and TestAdapter - like described here https://blogs.msdn.microsoft.com/devops/2018/01/30/mstest-v2-in-assembly-parallel-test-execution/

And then simply add this to your test project

[assembly: Parallelize(Workers = 4, Scope = ExecutionScope.ClassLevel)] 

EDIT: You can also disable parallel execution for a specific test using [DoNotParallelize] on a test method.

like image 200
Alex from Jitbit Avatar answered Sep 23 '22 07:09

Alex from Jitbit