Question

How to generate an HTML report from PartCover results .xml

Was it helpful?

Solution

There is a tool you can use to generate a HTML report:

https://github.com/danielpalme/ReportGenerator

Here you can find an article how to integrate the tool into MSBuild:

http://www.palmmedia.de/Blog/2009/10/30/msbuild-code-coverage-analysis-with-partcover-and-reportgenerator

OTHER TIPS

To my knowledge, there is no convenient tool like NCoverExplorer that can transform a PartCover results .xml file into a .html report, but there are some .xsl files that can be used to transform PartCover's results to .html in CruiseControl.NET: Using CruiseControl.NET with PartCover.

You could take those .xsl files from CruiseControl.NET and convert your PartCover results.xml using something like Sandcastle's XslTransform.exe.

By the way, if this happens to be related to TeamCity, the upcoming 5.0 release will include support for .NET coverage using PartCover or NCover. See the documentation for more informations. Otherwise ignore this paragraph ;-)

Easiest solution is probably to use msxsl, a simple command line transformer. I use it for exactly this purpose, and it's easy to integrate into your build system.

http://www.microsoft.com/downloads/details.aspx?FamilyID=2FB55371-C94E-4373-B0E9-DB4816552E41&displaylang=en

Maybe a complicated way of doing it, but I did this with the Simian xml report. Created an XSL file for the formatting, then wrote a dumb little console application;

private const string MissingExtension = "Please enter a valid {0} file, this is missing the extension.";
    private const string InvalidExtension = "Please enter a valid {0} file, the file provided has an invalid extension.";

    public static void Main(string[] args)
    {
        if (args.Length < 2)
        {
            System.Console.WriteLine("Please enter a xsl file and xml file full path.");
            return;
        }

        var xslFile = args[0];
        var xmlFile = args[1];

        if (!CheckFileNameFormat(xslFile, false))
            return;
        if (!CheckFileNameFormat(xmlFile, true))
            return;

        var transform = new XslCompiledTransform();
        // Load the XSL stylesheet.
        transform.Load(xslFile);
        // Transform xml file into an html using the xsl file provided.
        transform.Transform(xmlFile, xmlFile.Replace("xml", "html"));
    }

    private static bool CheckFileNameFormat(string fileName, bool isXmlFile)
    {
        var extension = isXmlFile ? "xml" : "xsl";

        // valida that the argument has a period
        if (fileName.IndexOf(".") < 1)
        {
            System.Console.WriteLine(string.Format(MissingExtension, extension));
            return false;
        }

        var filePieces = fileName.Split('.');
        // split on the period and make sure the extension is valid
        if (filePieces[filePieces.GetUpperBound(0)] != extension)
        {
            System.Console.WriteLine(string.Format(InvalidExtension, extension));
            return false;
        }

        return true;
    }

Then I can call it from a MSBuild file like so;

 <Target Name="RunSimian" DependsOnTargets="RebuildSolution">

<Exec IgnoreExitCode="true" Command="&quot;$(MSBuildProjectDirectory)\..\Build\Packages\Simian\simian-2.2.24.exe&quot; -formatter=xml:$(MSBuildProjectDirectory)\..\Build\Artifacts\simian.xml -language=cs -excludes=$(MSBuildProjectDirectory)\..\Product\Production\**\*.Designer.cs $(MSBuildProjectDirectory)\Production\**\*.cs" >
</Exec>

<Exec IgnoreExitCode="true" Command="&quot;$(MSBuildProjectDirectory)\..\Build\Packages\XmlToHtmlConverter.exe&quot; $(MSBuildProjectDirectory)\..\Build\Packages\Simian\simian.xsl $(MSBuildProjectDirectory)\..\Build\Artifacts\simian.xml">
</Exec>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top