We are writing C++ tests with the help of Microsoft Unit Testing Framework (https://learn.microsoft.com/en-us/visualstudio/test/how-to-use-microsoft-test-framework-for-cpp?view=vs-2022#run-the-tests)
Tests are running fine, it works within Visual Studio and on our CI/CD servers.
And we are happy with the suite.
But we start to have a lot of tests and we want to parallelize the tests.
When I activate the "Run tests in parallel" option in the test menu, or if I use the /Parallelize option of vstest.console.exe, the C++ tests are still run in sequential order, and there is no improvement to the duration of the tests.
It seems to work for C# tests but not for C++ written tests.
One simple repro, debug version compiled with Visual Studio 2022 (17.12.3):
vstest.console.exe mytests.dll
...
Total execution time = 5.1s
vstest.console.exe mytests.dll /Parallel
...
Total execution time = 5.1s
Is there a way to run parallel tests in C++ ?
Some hidden attributes ?
The C++ tests are quite simple:
namespace MyTests
{
TEST_CLASS(LengthyTests)
{
static int DoSomeLengthyCalculations(int loops)
{
int s = 0;
for (int i = 0; i<loops; i++)
{
for (int j = 0; j<1000; j++) s += 3;
s += 1;
for (int j = 0; j<1000; j++) s -= 3;
}
return s;
}
TEST_METHOD(First)
{ Assert::AreEqual(500'000, DoSomeLengthyCalculations(500'000)); }
TEST_METHOD(Second)
{ Assert::AreEqual(800'000, DoSomeLengthyCalculations(800'000)); }
}; }