22 July 2009

How to turn on code coverage when running unit tests in VSTS 2010

When running tests in Visual Studio Team System 2010, you can collect a lot of information about the code you’re testing and the environment the tests are running in. Previous versions were able to collect code coverage, but that’s was about it. VSTS 2010 provides a number of specific “collectors” that you can choose to enable for your tests. For instance, there is a collector for event log entries, system information and even a video recording of the test run (but this is not that interesting for unit tests :-)) The UI for enabling code coverage in VSTS 20210 has changed to accommodate these new features, and the code coverage settings is grouped together with the other collectors.

The easiest way to enable code coverage in VSTS 2010 is to open your existing Local.testsettings file (in VSTS 2008 these files had the extension testrunconfig), select the Execution Criteria category and enable Code Coverage in the list of Collectors:
image

Then you have to click the Advanced… button, which displays a dialog that is more or less equivalent to what you find when you select the Code Coverage category in the test run configuration in VSTS 2008. Here you select which assemblies you want to include in the code coverage:
image 

You might not always want to run your unit tests with code coverage, so I recommend clicking Save As... in the Configuration Settings dialog to create a new test settings file.

Another interesting feature of VSTS 2010 is that Visual Studio can now identify which test you should run when modifying your code. This feature is implemented by a collector named Test Impact Collector, and should reduce the number of test you run while coding to only include the ones covering the code you have modified. When you create a new unit test project in Visual Studio 2010, it adds an extra test settings file called TraceAndTestImpact.testingsettings for this purpose, but I haven’t used this feature enough to get a feeling of how effective this functionality yet. I hope to publish another post about this in the future though.

No comments:

Post a Comment