Integrating NCover and MSTest into my ccnet.config turned out to be relatively painless. I did have to do some trial and error when I decided to use the <exec> task rather than calling into a Nant or MSBuild script. I used this link to determine all the base information I needed to include.
Unit Tests & Code Coverage
The portion of the code snippet below contained within the <exec> task is the important part. I included the preceding xml for context only.
<cruisecontrol xmlns:cb="urn:ccnet.config.builder"> <!-- http://confluence.public.thoughtworks.org/display/CCNET/Configuration+Preprocessor --> <cb:define cmd.exe="c:\Windows\System32\cmd.exe" /> <cb:define ncover.console.exe="C:\Program Files (x86)\NCover\NCover.Console.exe" /> <cb:define ncover.reporting.exe="C:\Program Files\NCover\NCover.Reporting.exe"/> <cb:define mstest.exe="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe" /> <cb:define solution="Release" /> <project name="Project.Test"> <tasks> <exec> <executable>$(ncover.console.exe)</executable> <baseDirectory>$(work_dir)\$(projectName)\bin\$(configuration)</baseDirectory> <buildArgs>"$(mstest.exe)" /testcontainer:$(projectName).dll /resultsfile:results.xml //xml $(work_dir)\$(projectName)\bin\$(configuration)\coverage.xml</buildArgs> <buildTimeoutSeconds>1200</buildTimeoutSeconds> </exec>
Both MSTest and NCover parameters are included in the <buildArgs> section. The important thing to note here is the use of double slashes ‘//’ for NCover command line parameters as opposed to single slashes ‘/’ for MSTest parameters. This task produces a results.xml for MSTest and a coverage.xml for NCover. Both these files are included in the <merge> task below.
Generating Coverage Reports
The following <exec> task contains all necessary information for generating the full coverage HTML report.
<exec> <executable>$(ncover.reporting.exe)</executable> <baseDirectory>$(work_dir)\$(Project.Name)\bin\$(configuration)</baseDirectory> <buildArgs>$(work_dir)\$(Project.Name)\bin\$(configuration)\coverage.xml //or FullCoverageReport:Html //op $(work_dir)\$(Project.Name)\bin\$(configuration)\NCover\Reports</buildArgs> </exec> </tasks>
Merge HTML Reports for integration in Web Dashboard
Most of the information I found for integrating the Full Coverage HTML Report into ccnet was derived from this article. The only thing I had left to figure out on my own, was where to specify the ‘target’ folder. The ‘merge’ task does not copy recursively, so each subdirectory you need copied will have to be specified within it’s own ‘merge’ task.
<publishers> <merge target="Files"> <files> <file action="Copy">$(work_dir)\$(Project.Name)\bin\$(configuration)\ncover\reports\files\*.*</file> </files> </merge> <merge> <files> <file action="Copy">$(work_dir)\$(Project.Name)\bin\$(configuration)\ncover\reports\*.*</file> <file>$(work_dir)\$(Project.Name)\bin\$(configuration)\results.xml</file> <file>$(work_dir)\$(Project.Name)\bin\$(configuration)\CoverageReport.xml</file> </files> </merge> <xmllogger/> <statistics/> <rss/> </publishers> </project>
Add NCover Report Link to Dashboard
I included my complete ‘buildPlugins’ section of my dashboard.config file. The only line that needs to be added is the ‘htmlReportPlugin’ section.
I had used the default NCoverSummary.xsl prior to adding the html report. Because of this, I struggled with getting it to work until I commented out both sections for NCover that you see below. Once these sections were omitted the link worked flawlessly.
<buildPlugins> <buildReportBuildPlugin> <xslFileNames> <xslFile>xsl\header.xsl</xslFile> <xslFile>xsl\modifications.xsl</xslFile> <xslFile>xsl\MsTestSummary2008.xsl</xslFile> <!--xslFile>xsl\NCoverSummary.xsl</xslFile--> </xslFileNames> </buildReportBuildPlugin> <buildLogBuildPlugin /> <xslReportBuildPlugin description="MSTest Report" actionName="MSTESTReport" xslFileName="xsl\MsTestReport2008.xsl"/> <!--xslReportBuildPlugin description="NCover Report" actionName="NCoverReport" xslFileName="xsl\NCoverReporting30.xsl"/--> <htmlReportPlugin description="Full NCover Report" actionName="viewReport" htmlFileName="fullcoveragereport.html" /> </buildPlugins>
A couple of potential gotchas:
- In order to see the NCover link appear in the Dashboard, you may have to stop & restart your ‘ccnet’ web service. Instructions for this can be found here.
- If you are unable to drill down to the source level in the NCover report, check to see if the folders for the dll’s or exe’s you are testing contain their PDB files.


