VS 2010 supports running MS Tests in parallel. Most of the machines available in the market are multi-cpu / core machines. This will help us to increase the number of tests executing in same time, which will reduce total test time. But while writing tests, developers should make sure the tests are thread safe, if it is not, it may result in incorrect results, deadlocks etc.
You can enable parallel test execution by editing the testsettings file, instead of double click and open the test settings dialog, open the file using Open with option in the context menu, and select XML(Text) Editor option, which open the testsettings file in XML Editor. In the XML, find the Execution element. Add parallelTestCount attribute to the Execution element(By default it will not be there).

Parallel Test count attribute in testsettings file
By default it will be 1(if the attribute is not exists), other options are 0 for Auto configure we will use as many tests as we can based on your CPU and core count, and n, the number n of tests to run in parallel. Save the changes. Restart visual studio. And you are done.(Note: You need to restart visual studio, otherwise changes will not reflect.)
Here is a sample unit test
[TestMethod]
public void TestMethod3()
{
Console.WriteLine(Thread.CurrentThread.Name);
Thread.Sleep(2000);
}
Now I am running few test cases (11) with no parallelTestCount attribute and here is the Test Results window and summary

Test Results View - No attribute specified

Test Results summary - No attribute specified
Now I added the parallelTestCount attribute, with value of 5 and here is the Test Results window and summary, you can notice the time difference between two executions.

Test Results View - parallelTestCount Attribute specified

Test Results Summary - With parallelTestCount attribute specified
Of course there are many other factors that affect this. There is the cost of starting and tearing down the run, so you will see a lesser effect if you have a few tests. It also depends on the number of CPU/cores you have and of course how fast your tests execute.
Happy unit testing


Pingback: How to execute ms tests in parallel on... | .NET | Syngu