Yesterday I’ve installed the new VS2015 update and tried to make my machine talk to my win10 (IoT core) Raspberry PI. It didn’t help but that’s a story for another blog post. (Spoiler: it was a problem with my laptops Ethernet port.)
After the dust settled I’ve started reading about the new goodness that was just added to my trusty Visual Studio and found out that Microsoft has decided to give us the parallel test execution.
It all started back in the long forgotten Visual Studio 2010. Back then we had a great feature called parallel test execution. It did exactly that – reduce run speed by utilizing several cores to run tests — it was well hidden but for those of use who know where to enable it — it worked like a charm — as long as other tools, especially your Mocking framework of choice supported multi threading.
Then came VS2012 and the ability to run unit tests side by side disappeared… you could use it but for the price of using the old soon to be legacy test runner.
Since I liked the fact that my test run took less time I was happy to see that the feature I liked came back.
Enabling parallel tests is simple — first create a new test.runsetings — don’t look for a template (because there is none), just add a new xml file and rename it.
For parallel tests you just need the file to contain the following lines:
<?xml version="1.0" encoding="utf-8"?><RunSettings> <RunConfiguration> <MaxCpuCount>0</MaxCpuCount> </RunConfiguration></RunSettings>
For the value of MaxCpuCount use the number of threads you want to use (usually 1 for sequential run), or instead ‘0’ or a number greater of the number of your machine logical core (please use ‘0’).
Look under Test menu for “Select Test Settings File” and choose the newly minted (test settings) file.
For more information of what the test settings file can do for you — read this MSDN page.
Now when running the tests you’ll see improvement it the time it takes for them to finish.
I did notice that it took longer for the tests to start running and there’s a barely noticeable delay at the end of the run but other than that — parallel tests!
As you can see the runner runs assemblies in parallel so if you have a lot of tests in one assembly — you might not benefit from this feature, please consider splitting your tests (and probably production code as well).
I still need to check if (and which) mocking frameworks would work with this new(ish) test execution.