Some time ago somebody on Stackoverflow asked how to integrate OpenCover results into CruiseControl .NET. After being asked again, I decided to write a tutorial to show how CC.NET has to be configured.
I created a demo project that uses NUnit, OpenCover and ReportGenerator to generate HTML coverage reports that are integrated into CC.NET.
The archive CodeCoverage.7z (see 'Downloads') has to be extracted to C:\temp\
The following ccnet.config is used:
<cruisecontrol xmlns:cb="urn:ccnet.config.builder"> <!-- This is your CruiseControl.NET Server Configuration file. Add your projects below! --> <project name="CodeCoverageProject" description="Demo for integration of code coverage results in CC.NET"> <workingDirectory>C:\Temp\CodeCoverage\</workingDirectory> <triggers> <!-- check the source control every X time for changes, and run the tasks if changes are found --> <intervalTrigger name="continuous" seconds="120" buildCondition="IfModificationExists" initialSeconds="5"/> </triggers> <sourcecontrol type="nullSourceControl" alwaysModified="true"></sourcecontrol> <tasks> <exec> <executable>C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable> <buildArgs>CodeCoverage.sln /p:Configuration=Release /t:Build</buildArgs> </exec> <exec> <executable>tools\OpenCover\OpenCover.Console.exe</executable> <buildArgs>-register:user -target:tools\NUnit-2.6.1\bin\nunit-console.exe -targetargs:"/noshadow CodeCoverageTest\bin\Release\CodeCoverageTest.dll /xml=reports\TestResult.xml" -filter:+[*]* -output:reports\coverage.xml</buildArgs> </exec> <exec> <executable>tools\ReportGenerator\ReportGenerator.exe</executable> <buildArgs>"-reports:reports\coverage.xml" "-targetdir:$[$CCNetArtifactDirectory]\$[$CCNetLabel]\coveragereport"</buildArgs> </exec> </tasks> <publishers> <xmllogger /> <artifactcleanup cleanUpMethod="KeepLastXBuilds" cleanUpValue="50" /> </publishers> </project> </cruisecontrol>
This configuration does the following:
- The solution is compiled
- The Unit tests are executed by OpenCover
- ReportGenerator creates the HTML coverage report
The build script is pretty straight forward, the only thing that is important, is the target directory of ReportGenerator. The HTML report has to be placed in $[$CCNetArtifactDirectory]\$[$CCNetLabel]\coveragereport, otherwise CC NET will not be able to display it.
After configuring the server, you can now integrate the HTML coverage report into the Dashboard. Therefore we have to add the following line to dashboard.config (in the <buildPlugins> section):
<htmlReportPlugin description="Coverage Report" actionName="coverageReport" htmlFileName="coveragereport\index.htm" />
After restarting IIS, you can view the build results. The menu on the left side will contain a new item 'Coverage Report'. When you click on it, you will see the following view