Enabling Code coverage in Visual Studio 2005 on a network drive.

Alex van Buitenen, feb 2009

This document describes enabling code coverage in visual studio 2005 and the problems code coverage has to write to a network drive.
Working with unit tests is presumed familiar.

After adding a test project to your solution (see fig. 1), a test run configuration file is added to the Solution Items (see fig 2.)

fig 1. Adding a C# test project.

fig 2. The test run configuration file that was added.

By double-clicking the test configuration file, you can enable Code Coverage:

fig 3. Enabling Code Coverage.

Now, when you run your unit test and you're running from a network drive, you will get an error:

"Error VSP1368 : VSPerf logger does not support logging to network drives."

fig. 4. The error message.

To get around this error, you will have to edit the test configuration file with the XML Editor:

fig 5. Edit the test configuration file with the XML Editor:
 

Lookup "userDeploymentRoot" and "useDefaultDeploymentRoot" to change the location of the test to your local c: drive.
 

Old:
<userDeploymentRoot type="System.String" />
<useDefaultDeploymentRoot type="System.Boolean">True</useDefaultDeploymentRoot>

New:
<userDeploymentRoot type="System.String">c:\TestResults</userDeploymentRoot>
<useDefaultDeploymentRoot type="System.Boolean">False</useDefaultDeploymentRoot>

Now the Code Coverage will be able to write to the "c:" drive
However, your working directory will be "c:\TestResults"!

This might cause some problems when you are referring to test files with relative paths.
You can copy your test files easily to the "c:\TestResults" directory by using the Deployment Options of the test configuration file.
(this time use the test configuration editor instead of the XML editor):

fig. 6. Deploying test files.

Now, after running your unit tests, you can view the Code Coverage Results:

fig 7. Code Coverage is working!