How to run unit tests (MSTest) in parallel?

前端 未结 6 2035
独厮守ぢ
独厮守ぢ 2020-11-29 02:19

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

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

6条回答
  •  無奈伤痛
    2020-11-29 02:51

    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.

提交回复
热议问题