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).
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)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With