Getting code coverage result in drop folder during a TFS2010 buils

In a very old post I explained how to enable code coverage in TFS2010 builds and today I received a mail asking an interesting question.

The question is: Is it possible to have Code Coverage result to be included in drop folder?.

Answering this question is a two phase process, the first one is understanding where MsTest store results of code coverage and verify that is possible to do something useful with them. The answer is simple, you can simply look at the TestResult directory after you execute tests inside visual studio, and you will find a data.coverage file.

image

Figure 1: Test results does contains data.coverage file

If you open the file you find that this is a binary file, so it is really useful to have it copied on the Drop Folder? The answer is yes, because if you read this post, you will learn how to transform it into a XML file that can be human readable. You will find even some detail here, on how to create a stylesheet that convert the XML in something more readable, another Xsl stylesheet can be found here.

I must admit that I never tried those solutions, but the conclusion is: from a.coverage file is possible to extract useful data outside Visual Studio.

Now we should solve the other problem: how to have this data available on the drop folder after a TFS2010 Build is completed. A really quick and dirty way is to edit the workflow used in the build to copy the entire test result folder in the Drop Folder.

image

Figure 2: Copy all test results folder in drop location.

This modification simply copy the whole TestResults directory, from the folder where the build occours (variable TestResultDirectory) to the drop folder directory (BuildDetail.DropLocation variable).

image

Figure 3: Test results gets copied into the drop folder.

As you can verify, after a build, the entire TestResults folder is copied to the drop folder, so you can anlyze code coverage result with the tool you prefer.

This is a simply and dirty way to copy everything related to test result to the drop folder, you can issue a more intelligent command (even a xcopy.exe) that copy only the data.coverage if you are only interested in that file.

alk.