I am expecting vstest.console.exe will run all test methods in parallel with /Parallel
option specified. On a 4 core machine, I am expecting below test class will cost around 2~3 seconds for execution, by actually I got 8~9 seconds which means the tests are executed sequentially.
[TestClass]
public class UnitTest1
{
[TestMethod]
public async Task TestMethod1()
{
await Task.Delay(2000);
}
[TestMethod]
public async Task TestMethod2()
{
await Task.Delay(2000);
}
[TestMethod]
public async Task TestMethod3()
{
await Task.Delay(2000);
}
[TestMethod]
public async Task TestMethod4()
{
await Task.Delay(2000);
}
}
The test ouput:
Microsoft (R) Test Execution Command Line Tool Version 15.5.0 Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait... Passed TestMethod1 Passed
TestMethod2 Passed TestMethod3 Passed TestMethod4Total tests: 4. Passed: 4. Failed: 0. Skipped: 0. Test Run Successful.
Test execution time: 8.6960 Seconds
You will be needing a setting file inorder to tell how many core you want to use for the execution.
command will be something like this:
vstest.console.exe /Parallel MyUnitTest.dll /Settings:C:\Settings.testsettings
And the Settings.testsettings should be something like this:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<MaxCpuCount>0</MaxCpuCount>
</RunConfiguration>
</RunSettings>
The value for MaxCpuCount has the following semantics:
‘n’ (where 1 <= n <= number of cores): upto ‘n’ processes will be launched. ‘n’ of any other value: The number of processes launched will be as many as the available cores on the machine. Typically, a value of 0 indicates that up to all of the available free cores may be used.
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