How to run unit tests (MSTest) in parallel?

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.

Leave a Comment