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

Parsing output from vstest.console.exe command line tool

Jul 2, 2013 at 3:19 PM
Hi,

on your home page you mention that your tool is compatible with vstest.console.exe command line tool.

Can you please provide an example how to parse the coverage output file created by vstest?

When I try the below command, I get an error stating "Error during reading report ... Data at the root level is invalid. Line 1, position 1.".
ReportGenerator.exe "-reports:c:\TestResults\SomeGuid\SomeUser_ 2013-07-02 16_41_03.coverage" -targetdir:c:\report -reporttypes:Html
The coverage file is created with the following command:
"c:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"  MyTestAssembly.dll  /Platform:x64 /InIsolation /EnableCodeCoverage
regards,
Esge
Coordinator
Jul 3, 2013 at 12:42 PM
Hi Esge,

if you execute your tests in Visual Studio, you can export the coverage to an *.coveragexml file (see this explanation: http://stackoverflow.com/a/4938700/203416).
This file can be parsed by ReportGenerator. ReportGenerator is currently not able to process *.coverage files directly.

The conversion only works with Visual Studio Premium and Ultimate. And only in Visual Studio, not on the command line.

But there is an easy way to manually convert the .coverage to an .coveragexml:

Create a new command line project in Visual Studio and add a reference to C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Coverage.Analysis.dll

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

namespace CoverageConverter
{
    class Program
    {
        static void Main(string[] args)
        {
            using (CoverageInfo info = CoverageInfo.CreateFromFile("data.coverage", 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 10.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Coverage.Symbols.dll to the output directory of your project.

For Visual Studio 2012 you will find the DLLs in this directory: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies

I would like to add this code to ReportGenerator, but that's not possible, since I can't add the Visual Studio DLLs to my project.

Hope this helps.
Jul 9, 2013 at 7:00 AM
Thank you for the explanation. I built the conversion tool according to your instructions and it works nicely. And the report is great. Thanks again.