views:

1145

answers:

6

Hi, I'm trying to get PartCover reports to generate correctly in TeamCity 5.0. When I click the Code Coverage tab in the build details, the reports are empty.

I'm using the sln2008 build agent and my PartCoverage settings are as follows:

Include Patterns:

[*]*

Report XSLT:

C:\Program Files\PartCover .NET 2.3\xslt\Report By Assembly.xslt=>ByAssembly.html
C:\Program Files\PartCover .NET 2.3\xslt\Report By Class.xslt=>ByClass.html

Bonus points if you can describe how to include those reports (or just the important parts) with the email that TeamCity sends for successful/failed builds. I would like to continue using the sln2008 build agent, if possible, and not a different build agent.

A: 

Please check tests are running under x86. Make sure partcover is installed to the C:\Program Files\PartCover .NET 2.3\xslt on the build agent machine.

Please check build agent windows service is running under administrator user accound, but not under LOCAL SYSTEM account.

Eugene Petrenko
That's all setup correctly. I'm still getting "empty" reports.Also, I did originally have the build agent service set to local system with "Allow service to interact with Desktop" checked. Is that acceptable as well, or must it run under an admin user account? Btw, I do currently have it set as a local admin user account, with no luck.
Jim Geurts
It's recommended to run build agent service under some real administrator account. Please attach the produced PartCover result file, please check the file's structure matches xslt that you used.Produced result should be added as artifact.
Eugene Petrenko
+1  A: 

The problem may just be the xsl - I initially assumed that the files installed with partcover would work without modification, but it seems not to match the input file - the first significant line is

<xsl:for-each select="/PartCoverReport/type">

which is quite different from

<xsl:for-each select="/PartCoverReport/Type">

The calculations for code size also appear to be wrong - it should be ./Method/pt rather than ./method/code/pt

Tom Clarkson
+5  A: 

I had the same problem with the PartCover reports. So I have been trying to make it work right and I just discovered that the problem was the two XSLT files that come with the PartCover distribution.

I fixed these files and now everything is working fine for me:

report by assembly

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt">
  <xsl:output method="html" indent="yes"/>
    <xsl:template match="/">

    <xsl:variable name="cov0style" select="'background:#E79090;text-align:right;'"/>
    <xsl:variable name="cov20style" select="'background:#D79797;text-align:right;'"/>
    <xsl:variable name="cov40style" select="'background:#D7A0A0;text-align:right;'"/>
    <xsl:variable name="cov60style" select="'background:#C7A7A7;text-align:right;'"/>
    <xsl:variable name="cov80style" select="'background:#C0B0B0;text-align:right;'"/>
    <xsl:variable name="cov100style" select="'background:#D7D7D7;text-align:right;'"/>

<table style="border-collapse: collapse;">
  <tr style="font-weight:bold; background:whitesmoke;">
    <td colspan="2">Coverage by assembly</td>
  </tr>

  <xsl:variable name="asms" select="/PartCoverReport/Assembly"/>
  <xsl:for-each select="$asms">
    <xsl:variable name="current-asm-node" select="."/>
    <tr>

      <xsl:element name="td">
        <xsl:attribute name="style">background:ghostwhite; padding: 5px  30px 5px  5px;</xsl:attribute>
        <xsl:value-of select="$current-asm-node/@name"/>
      </xsl:element>

      <xsl:variable name="codeSize" select="sum(/PartCoverReport/Type[@asmref=$current-asm-node/@id]/Method/pt/@len)+0"/>
      <xsl:variable name="coveredCodeSize" select="sum(/PartCoverReport/Type[@asmref=$current-asm-node/@id]/Method/pt[@visit>0]/@len)+0"/>

      <xsl:element name="td">
        <xsl:if test="$codeSize=0">
          <xsl:attribute name="style">
            <xsl:value-of select="$cov0style"/>
          </xsl:attribute>
          0%
        </xsl:if>
        <xsl:if test="$codeSize &gt; 0">
          <xsl:variable name="coverage" select="ceiling(100 * $coveredCodeSize div $codeSize)"/>
          <xsl:if test="$coverage &gt;=  0 and $coverage &lt; 20">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov20style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage &gt;= 20 and $coverage &lt; 40">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov40style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage &gt;= 40 and $coverage &lt; 60">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov60style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage &gt;= 60 and $coverage &lt; 80">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov80style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$coverage &gt;= 80">
            <xsl:attribute name="style">
              <xsl:value-of select="$cov100style"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:value-of select="$coverage"/>%
        </xsl:if>
      </xsl:element>
    </tr>
  </xsl:for-each>
</table>

report by class

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt">
<xsl:output method="html" indent="no"/>

<xsl:template match="/">

<xsl:variable name="cov0style" select="'background:#FF4040;text-align:right;'"/>
<xsl:variable name="cov20style" select="'background:#F06060;text-align:right;'"/>
<xsl:variable name="cov40style" select="'background:#E78080;text-align:right;'"/>
<xsl:variable name="cov60style" select="'background:#E0A0A0;text-align:right;'"/>
<xsl:variable name="cov80style" select="'background:#D7B0B0;text-align:right;'"/>
<xsl:variable name="cov100style" select="'background:#E0E0E0;text-align:right;'"/>

<table style="border-collapse: collapse;">
    <tr style="font-weight:bold; background:whitesmoke;"><td colspan="2">Coverage by class</td></tr>

    <xsl:for-each select="/PartCoverReport/Type">
        <tr>

            <xsl:element name="td">
                <xsl:attribute name="style">background:ghostwhite; padding: 5px  30px 5px  5px;</xsl:attribute>
                <xsl:value-of select="@name"/>
            </xsl:element>

            <xsl:variable name="codeSize" select="sum(./Method/pt/@len)+0"/>
            <xsl:variable name="coveredCodeSize" select="sum(./Method/pt[@visit>0]/@len)+0"/>

            <xsl:element name="td">
                <xsl:if test="$codeSize=0">
                    <xsl:attribute name="style"><xsl:value-of select="$cov0style"/></xsl:attribute>
                    0%
                </xsl:if>

                <xsl:if test="$codeSize &gt; 0">
                    <xsl:variable name="coverage" select="ceiling(100 * $coveredCodeSize div $codeSize)"/>

                    <xsl:if test="$coverage &gt;=  0 and $coverage &lt; 20"><xsl:attribute name="style"><xsl:value-of select="$cov20style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage &gt;= 20 and $coverage &lt; 40"><xsl:attribute name="style"><xsl:value-of select="$cov40style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage &gt;= 40 and $coverage &lt; 60"><xsl:attribute name="style"><xsl:value-of select="$cov60style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage &gt;= 60 and $coverage &lt; 80"><xsl:attribute name="style"><xsl:value-of select="$cov80style"/></xsl:attribute></xsl:if>
                    <xsl:if test="$coverage &gt;= 80"><xsl:attribute name="style"><xsl:value-of select="$cov100style"/></xsl:attribute></xsl:if>
                    <xsl:value-of select="$coverage"/>%
                </xsl:if>

            </xsl:element>
        </tr>
    </xsl:for-each>
</table>    
</xsl:template>
</xsl:stylesheet>

I hope you find this useful. Also, any feedback about this files is welcomed, so we can provide the commutiy with correct files.

yeyeyerman
Report by assembly is missing some closing tags
Sam Mackrill
I've extended this report with method-level coverage details, see the link in my answer below.
Gaspar Nagy
+2  A: 

Just having run through this problem myself. I thought I solved the issue by using yeyeyerman's answer. Indeed, it will build, but reading the build report I could see the "report by assembly" couldn't be compiled. Reason was that "report by assembly" was missing 2 lines of xml at the very end:

</xsl:template>
</xsl:stylesheet>

Adding that to the end of the file solved the stylesheet compilation issue, as the tags weren't properly closed before :).

Stenner
+1  A: 

Thank you very much for the information above. By using the xslt's from yeyeyerman and setting the windows service to use an admin id, everything is now running great and I have code coverage at last.

Great help - thanks everyone.

Ste

stfinch
+2  A: 

After playing a little bit with the fixed reports from yeyeyerman, I've finally created a completely new XSLT report, that also contains method-level coverage details and some other interesting stuff.

You can download the XSLT from my blog post here: http://gasparnagy.blogspot.com/2010/09/detailed-report-for-partcover-in.html

Gaspar Nagy