3

I am helping with a big codebase, and I found that [TestMethod] executions might interferer with each other if they run in parallel. I know that this is a bad practice.

Is there any way (like a C# attribute) to prevent parallel execution of all tests in a [TestClass]?

The tests are running automated in a few environments, including Azure DevOps. I am looking for a way to solve this matter in c# code and avoid using settings depends on the test runner.

Update and clarification #1

I know we have questions like this one dated back in 2009:

MSTest executing all my tests simultaneously breaks tests - what to do

Fast forward 11 years to 2020, I expect visual studio product family is a diffrent thing with the same name.

Update and clarification #2

This is not an NUnit question. The lazer forcus of this question is MStest.

Update and clarification #3

Please note that this is a product (MSTest) specific question. I know there are many similar questions related NUnit etc. or older version of Visual Studio.

As we know Visual Studio 2019 introduced many testing improvements. That is what I am asking.

Allan Xu
  • 7,998
  • 11
  • 51
  • 122
  • 1
    @PavelAnikhouski, please note the date of the question. After so many years we are taling about a totally diffrent product, same name. Let me add the version number and clarification. – Allan Xu May 13 '20 at 18:16
  • Could you find a solution? I am facing the same issue now. – Antiohia Nov 06 '20 at 17:28

1 Answers1

1

Either use DoNotParallelize attribute on method/class/assembly, or put DisableParallelization in your .runsettings file.

Ref, and much more about parallelization: https://devblogs.microsoft.com/devops/mstest-v2-in-assembly-parallel-test-execution

Jonathan
  • 6,939
  • 4
  • 44
  • 61