This project has moved. For the latest updates, please go here.

Visual Studio Coverage Tools

vstest.console.exe

By default vstest.console.exe creates a *.coverage file. To generate a coverage report with ReportGenerator the file has to be converted to *.xml format.

To get the *.coverage file you can use the following command:
"c:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "PATH_OF_YOUR_EXECUTABLE_OR_DLL" /InIsolation /EnableCodeCoverage

Now you should create a simple command line tool that converts the *.coverage file to *.xml format.
Create a new command line project in Visual Studio and add a reference to "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Coverage.Analysis.dll".

Add the following code (paths are hard coded here, but could be supplied as arguments):
using Microsoft.VisualStudio.Coverage.Analysis;

namespace CoverageConverter
{
    class Program
    {
        static void Main(string[] args)
        {
            using (CoverageInfo info = CoverageInfo.CreateFromFile(
                "PATH_OF_YOUR_*.coverage_FILE", 
                new string[] { @"DIRECTORY_OF_YOUR_DLL_OR_EXE"}, 
                new string[] { }))
            {
                CoverageDS data = info.BuildDataSet();
                data.WriteXml("converted.coveragexml");
            }
        }
    }

Before executing your tool, you have to copy "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Coverage.Symbols.dll" to the output directory of your project.

CodeCoverage.exe

CodeCoverage.exe is another coverage tool that comes with Visual Studio 2012 (Premium and Ultimate).
By default CodeCoverage.exe creates a *.coverage file. To generate a coverage report with ReportGenerator the file has to be converted to *.xml format.

To get the *.xml file you can use the following command:
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" collect /output:DynamicCodeCoverage.coverage "PATH_OF_YOUR_EXECUTABLE_OR_DLL"
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:DynamicCodeCoverage.coveragexml DynamicCodeCoverage.coverage

Last edited Jul 9, 2013 at 7:47 AM by danielpalme, version 1