Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallel option for vstest.console.exe does not work as expected

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 TestMethod4

Total tests: 4. Passed: 4. Failed: 0. Skipped: 0. Test Run Successful.

Test execution time: 8.6960 Seconds

like image 246
Shuping Avatar asked Feb 09 '18 09:02

Shuping


1 Answers

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.

like image 92
shrot Avatar answered Oct 28 '22 05:10

shrot