In Visual Studio 2010, we introduced the ability to run tests in parallel. Many machines today have multiple CPU’s or a CPU with multiple cores, so it makes sense that we may want our tests to run in such a way to use all the cores we have available on our machine. This will effectively increase the number of tests running at the same time, which will reduce the time to run all the tests.
We looked at all the different test types and functionality that we have, and made the following decisions:
So, you ask, get on with telling me what I need to do!
Okay, but first we must remind you, and it also kind of goes without saying, but I will say it anyway; you need a machine with multiple cores. Virtual machines can be used but you will need to make sure that the machine has multiple CPU’s. An easy way to find out is to view the task manager.
My machine is single CPU, but has multiple cores.
Also, your tests must be thread-safe. Only you can ensure that they are. Failure to do so can result in incorrect results, deadlocks, and a lot of head-aches. Take some time to review the thread-safe link and review your code for thread-safety.
Okay, so now, how do we do it? I will put all the steps from above into this list
I have two cores, and so here is my resulting run:
As you can see, we have two tests running at the same time. If we were running this in serial, we would at least take 10 seconds. With parallel tests we got this down to 6 seconds
Of course there are many other factors that affect this number. 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.
Good luck and hope this helps speed things up for you.
Bruce Taimana Program Manager Visual Studio Team Test