Chris Alexander

On Engineering

Nice code coverage results

Cleaning up code coverage in VSO

13th November, 2015

As part of my experiments with Visual Studio 2015 (and phasing out Resharper from my life) I have been giving VSO a go to get a feel for how it works compared to Github and other systems (such as legacy TFS).

One thing that always bugged me about using Visual Studio’s built in code coverage is that it always seemed to cover everything, including your test runner DLLs and your test DLLs themselves. Really I only want coverage analysis of the code under test rather than everything in the directory!

Now I have had time to put the effort in and figure out how to get it working. Thanks to these posts (and MSDN) I have got something working rather nicely.

Step 1: .runsettings

You need to create a runsettings file for use in your solution.

Create a new XML file, call it something descriptive like “CodeCoverage.runsettings”, and make sure it is added at the solution level rather than the project level:

(No alt specified)

I have created an example file that I now use. This is designed specifically to exclude DLLs that end “Tests.dll” (which is how my test projects are named), as well as xunit, xbehave, and fluentassertions, which are the projects I am using for testing.

Step 2: Use the settings file locally

Under the Test -> Test Settings menu, use Select Test Settings File and pick your .runsettings file. Run the code coverage locally to check that your output excludes the correct DLLs.

Step 3: Use the settings as part of VSO build

In your VSO build (assuming you are using the new workflow), under the Visual Studio Test step, set your RunSettingsFile to the relative path from your root directory to the runsettings file. Mine is in the root next to the solution file, so it looks like this:

(No alt specified)

Now you should be able to see the reduced coverage in your ouput in VSO builds as well.