Skip to end of metadata
Go to start of metadata

MSTest Coverage

MSTests can compute Code Coverage Statistics, but its only output is in binary form. To be able to generate reports, this binary must be transformed to XML. Thankfully, Microsoft provides an interface to do just so, and someone created a MSBuild task for this :

This MSBuild tasks creates a xml report that can now be exploited to create a nice Coverage Report.

In order to avoid writing a new hudson plugin from scratch, a XSL Transformation was devised that transformed MSTest's Coverage report into a Emma Coverage report, so the Emma hudson plug-in can display the reports.

The said XSL in attached to this page.

You have to run the XSLT yourself for now (an MSBuild Exec task can do it, provided you have msxsl at hand) :

<Exec Command="msxsl.exe $(SolutionDir)\$(RunConfig)\In\$(ComputerName)\data.xml $(DevToolsDir)\MSTestCoverageToEmma.xsl -o $(SolutionDir)\coverage.xml" />
  • No labels

1 Comment

  1. Unknown User (olidag)

    There's a bug in the stylesheet (version 1, dated Oct 28, 2009): it assumes code coverage is only being measured for one assembly (module). The fix is to compute the sum of the numbers from all the modules. Replace the declarations of CoveredBlocks, TotalBlocks, TotalLines and CoveredLines with the following:

    <xsl:variable name="CoveredBlocks"><xsl:value-of select="sum(Module/BlocksCovered)"/></xsl:variable>
    <xsl:variable name="TotalBlocks"><xsl:value-of select="sum(Module/BlocksCovered) + sum(Module/BlocksNotCovered)"/></xsl:variable>
    <xsl:variable name="TotalLines"><xsl:value-of select="sum(Module/LinesCovered) + sum(Module/LinesPartiallyCovered) + sum(Module/LinesNotCovered)"/></xsl:variable>
    <xsl:variable name="CoveredLines"><xsl:value-of select="sum(Module/LinesCovered)"/></xsl:variable>


    • Oli