Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Test do not run in Parallel even though that option is selected through the UI

This seems like a pretty basic issue, but Microsoft has had issues running unit tests in parallel for several versions of Visual Studio. The only way we found that would work previously (using both a .runsettings and a deprecated .testsettings file) no longer seems to work, probably due to MSTest v2. The latest documentation for the .runsettings file (https://learn.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2019) is no help, as the setting there has no effect (at least in our use case).

like image 774
James Avatar asked Oct 22 '25 07:10

James


1 Answers

After much googling, following links, reading, and testing, I finally found the answer in a link on this page: https://marketplace.visualstudio.com/items?itemName=OsirisTerje.Runsettings-19151:

<RunSettings>
<!-- MSTest adapter -->  
  <MSTest>
    <Parallelize>
      <Workers>4</Workers>
      <Scope>ClassLevel</Scope>
    </Parallelize>
  </MSTest>
</RunSettings>

It seems this didn't make it into the documentation for some reason, but this change finally triggered parallel MSTEST unit tests in VS2019.

UPDATE:

I've found an even better link: https://devblogs.microsoft.com/devops/mstest-v2-in-assembly-parallel-test-execution/ This indicates that you can also set <Scope> to MethodLevel or Custom, and you can also add an assembly attribute like the following

[assembly: Parallelize(Workers = 4, Scope = ExecutionScope.ClassLevel)]
like image 147
James Avatar answered Oct 23 '25 20:10

James



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!