views:

1244

answers:

5

How to generate an HTML report from PartCover results .xml

+1  A: 

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 ;-)

Cygon
Oh wait, I know that name. You're one of the TeamCity developers! In that case, ignore my last paragraph. It's a small world after all :)
Cygon
@Cygon: LoL dude, the last paragraph is funny :)
Piotr Owsiak
+1  A: 

You can use a programme like xalan which make XSL Transformation (XSLT)

Use it like that :

java -cp xalan.jar org.apache.xalan.xslt.Process -in <xmlSource> -xsl <stylesheet> 
  -out <outputfile>
  • xmlSource is your xml report
  • stylesheet can be one of xslt file distributed with PartCover (see xslt\ dir)
  • outputfile is your html report
Damien Carol
Have you tested this solution ?
Damien Carol
I start using java xslt inside existing java process. Thanks!
Eugene Petrenko
A: 

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>

Jeff Spicoli
A: 

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&amp;displaylang=en

nullptr
+2  A: 

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

http://www.palmmedia.de/Net/ReportGenerator

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

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

Daniel
I've tried it. This tool was very slow.
Eugene Petrenko
How long did it take? I use the tool in our build with a 12MB report file and about 1200 classes with 300000 lines of code, and it takes 2-3 minutes on a slow machine.
Daniel