Integrating Code Coverage Reports with CruiseControl.NET
Setting up CruiseControl.NET to generate an NCoverExplorer code coverage report at the end of every build is the last step in a completly automated build process. The code coverage report provides an "at-a-glance" overview of the project's status, as shown in the following two pictures (click for a larger version).
Unfortunately, several steps are necessary to integrate NCoverExplorer code coverage reports with CruiseControl.NET.
First, several xslt files need to be copied to a CruiseControl.NET subdirectory. Which subdirectory depends on what type of report you want to see. If you want to receive NCoverExplorer reports in your email after a CruiseControl.NET build, place the xslt files in the server\xsl subdirectory (of course, you must also tell CruiseControl.NET to send you emails after a build). However, if you just want to see the report on the dashboard, place the xslt files in the webdashboard\xsl subfolder of the CruiseControl.NET install (typically located under C:\Program Files\CruiseControl.NET\).
The xslt files that convert NCoverExplorer's xml coverage report into visual html are placed in the C:\Program Files\NCover\CC.NET\ directory when NCover is installed, and they need to be copied to CruiseControl.NET's xsl folders. The files that need to be copied are:
- NCoverExplorer.xsl
- NCoverExplorer-Legacy.xsl
- NCoverExplorerSummary.xsl
- NCoverExplorerSummary-Legacy.xsl
Second, the webdashboard\dashboard.config file needs to be edited.
Change this line
<xslFile>xsl\NCover.xsl</xslFile>
to this line
<xslFile>xsl\NCoverExplorerSummary.xsl</xslFile>
Also change this next line from this
<xslReportBuildPlugin description="NCover Report" actionName="NCoverBuildReport" xslFileName="xsl\NCover.xsl" />
to this
<xslReportBuildPlugin description="NCover Report" actionName="NCoverBuildReport" xslFileName="xsl\NCoverExplorer.xsl" />
Third, modify your build script to call NCoverExplorer.Console and tell it to create a report from NCover's coverage data output. Here is an example MSBuild script to do that:
<UsingTask TaskName="NCoverExplorer.MSBuildTasks.NCoverExplorer"
AssemblyFile="C:\Program Files\NCover\Build Task Plugins\NCoverExplorer.MSBuildTasks.dll"/>
<Target Name="CreateReport">
<NCoverExplorer
ToolPath="C:\Program Files\NCover\"
ProjectName="MyProject"
OutputDir="myoutputpath"
ReportType="ModuleClassSummary"
XmlReportName="CoverageSummary.xml"
CoverageFiles="NCoverCoverage.xml" />
</Target>
and here is a NAnt script that does the same thing
<target name="CreateReport">
<ncoverexplorer
program="C:\Program Files\NCover\NCoverExplorer.Console.exe"
projectName="NCoverExplorer"
outputDir="myoutputpath"
reportType="ModuleClassSummary"
xmlReportName="CoverageSummary.xml" >
<fileset>
<include name="${coverage.xml.file}"/>
</fileset>
</ncoverexplorer>
</target>
NCoverExplorer has many more configuration options available than are presented here. Check out the documentation and example scripts in the "NCover\Build Task Plugins\" directory, or browse it online. And of course, NCoverExplorer offers many report options. Choose the one that fits your needs best.
Finally, open the CruiseControl.NET configuration file ("server\ccnet.config" under the CC.NET installation folder) and add the highlighted line.
<publishers>
<merge>
<files>
<file>Main\Test\NUnitResults-Release.xml</file>
<file>Main\Test\NUnitResults-Debug.xml</file>
<file>myoutputpath\CoverageSummary.xml</file>
</files>
</merge>
<!-- omitted code here -->
</publishers>
That's it! Now when CruiseControl.NET does a new build, the coverage data will be included in the report.