Hello,

This is a little tricky.
First you have to convert the binary data to xml. Lucky us Microsoft is giving 
us the ability to do that with a few lines of code.

1)    Create a new Console Application in VS. I named it mstest2xml

2)    Add <Visual Studio Installation 
Folder>\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Coverage.Analysis.dll
 to References

3)    Copy this code:
static void Main(string[] args)
        {
            string CoveragePath = args[0];
            string CoverageFile = args[1];
            string OutputFile = args[2];
            // Create a coverage info object from the file
            CoverageInfoManager.SymPath = CoveragePath;
            CoverageInfoManager.ExePath = CoveragePath;

            CoverageInfo ci = 
CoverageInfoManager.CreateInfoFromFile(CoverageFile);
            // Ask for the DataSet
            // The parameter must be null
            CoverageDS data = ci.BuildDataSet(null);

            // Write to XML
            data.WriteXml(OutputFile);
}

4)    Now you have an xml File that can be added in cruisecontrol.

5)    I Named the UnitTest only XXX_TestResults without a timestamp so it is 
easier to locate the file. In should be located in 
<ArtifactFolder\XXX_TestResult\In\<MachineName>\data.coverage

6)    in the merge-Block add the trx and the generated xml file

7)    To show the Unittest in the statistics add
<statistics>
                    <statisticList>
                        <statistic name='TestFailures' xpath='sum(//@failed)' />
                       <statistic name='TestIgnored' 
xpath='sum(//@inconclusive)'/>
                        <statistic name='TestCount' xpath='sum(//@total)' />
                    </statisticList>
                </statistics>
     but since that is not the question I think you already know that.

8)    Make an xslt-File to convert the raw data to a nice page. I found an 
example on the internet but that shows only a few data, does not sort and works 
only if there is only one test result. So I created my own since I have 
multiple test-classes in my project.

9)    Here is the code just copy it to the xls folder in the webdashboard
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
     <xsl:param name="low_coverage" select="30"/>
     <xsl:param name="ok_coverage" select="10"/>
     <xsl:template match="/">
              <html>
                       <body>
                                 <h1>This is the coverage report</h1>
                                 <h2>Assembly coverage</h2>
                                 <table style="width:640;border:2px solid 
black;">
                                          <tr>
                                                    <td 
style="font-weight:bold">Assembly</td>
                                                    <td 
style="text-align:right;font-weight:bold">Blocks covered (absolute)</td>
                                                    <td 
style="text-align:right;font-weight:bold">Blocks not covered (absolute)</td>
                                                    <td 
style="text-align:right;font-weight:bold">Blocks covered (percent)</td>
                                                    <td 
style="text-align:right;font-weight:bold">Blocks not covered (percent)</td>
                                          </tr>
                                          <xsl:for-each 
select="cruisecontrol/build/CoverageDSPriv/Module">
                                                    <xsl:sort 
select="ModuleName"/>
                                                    <tr>
                                                             <td>
                                                                      
<xsl:value-of select="ModuleName"/>
                                                             </td>
                                                             <td 
style="text-align:right">
                                                                      
<xsl:value-of select="BlocksCovered"/>
                                                             </td>
                                                             <td 
style="text-align:right">
                                                                      
<xsl:value-of select="BlocksNotCovered"/>
                                                             </td>
                                                             <td>
                                                                      
<xsl:variable name="pct2" select="(BlocksCovered div (BlocksNotCovered + 
BlocksCovered))*100"/>
                                                                      
<xsl:attribute name="style">text-align:right;
                                                                                
<xsl:choose>
                                                                                
         <xsl:when test="number($pct2 &lt;= 
$low_coverage)">background-color:red;</xsl:when>
                                                                                
         <xsl:when test="number($pct2 &lt;= 
$ok_coverage)">background-color:yellow;</xsl:when>
                                                                                
         <xsl:otherwise>background-color:green;</xsl:otherwise>
                                                                                
</xsl:choose>
                                                                      
</xsl:attribute>
                                                                      
<xsl:value-of select="format-number($pct2, '##0.00')"/>
                                                             </td>
                                                             <td>
                                                                      
<xsl:variable name="pct" select="(BlocksNotCovered div (BlocksNotCovered + 
BlocksCovered))*100"/>
                                                                      
<xsl:attribute name="style">text-align:right;
                                                                                
<xsl:choose>
                                                                                
         <xsl:when test="number($pct &gt; 
$low_coverage)">background-color:red;</xsl:when>
                                                                                
         <xsl:when test="number($pct &gt; 
$ok_coverage)">background-color:yellow;</xsl:when>
                                                                                
         <xsl:otherwise>background-color:green;</xsl:otherwise>
                                                                                
</xsl:choose>
                                                                      
</xsl:attribute>
                                                                      
<xsl:value-of select="format-number($pct, '##0.00')" />
                                                             </td>
                                                    </tr>
                                          </xsl:for-each>
                                 </table>
                       </body>
              </html>
     </xsl:template>
</xsl:stylesheet>
10.) Add to dashboard.config: <xslReportBuildPlugin description="MSTest 
Coverage" actionName="MSTest2008Cover" xslFileName="xsl\MsTestCover.xsl"/>




Regards,
Michael Schöller

From: [email protected] [mailto:[email protected]] On 
Behalf Of Craig & Sammi Sutherland
Sent: Wednesday, August 05, 2009 3:49 AM
To: [email protected]
Subject: [ccnet-user] Re: MSTEST Code Coverage results displaying in CCNET

It is not possible to use binary data in CC.NET dashboard or e-mail - it has to 
be in an XML format.


Craig

From: [email protected] [mailto:[email protected]] On 
Behalf Of Ammar Gangardiwala
Sent: Wednesday, 5 August 2009 1:16 p.m.
To: [email protected]
Subject: [ccnet-user] MSTEST Code Coverage results displaying in CCNET

I am having trouble MSTEST Code Coverage results displaying in CCNET.

My code coverage file is generated and it is in specific folder with file name 
as data.coverage.

Since this is in binary format how can i display the results in CCNET dashboard 
and email publishing? Your help will be appreciated

--
Thank you,
.NET Architect
Ammar Gangardiwala

Reply via email to