Daniel Palme

Daniel Palme

.NET consultant from Germany.

Blog > CruiseControl .NET - Integration of coverage reports

CruiseControl .NET - Integration of coverage reports

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.

Prerequisites

The archive CodeCoverage.7z (see 'Downloads') has to be extracted to C:\temp\

Server configuration

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 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

CCNET - Code Coverage

Downloads

CodeCoverage.7z

 

Related posts

 

New comment

:

:

:

:

 

Comments

#1
Anand

Anand

04/10/2013

Hi Please can u please let me know where is CCNetArtifactDirectory ?
I see only 3 folders inside CCNET install folder:

C:\Program Files\CruiseControl.NET\server
C:\Program Files\CruiseControl.NET\webdashboard
C:\Program Files\CruiseControl.NET\Examples
 
#2
Daniel

Daniel

04/10/2013

@Anand:
I'm sorry, I don't have CruiseControl installed right now.
But it should not be too hard to find, if you take a look at the log files of your build.
 
#3
Anand

Anand

04/10/2013

Hi Daniel,

I found the solution. It is defined in CCNET.config file.
<project name="Test Build">
<webURL>/</webURL>
<workingDirectory></workingDirectory>
<artifactDirectory></artifactDirectory>
<modificationDelaySeconds>600</modificationDelaySeconds>


 
#4
ANAND

ANAND

04/10/2013

One more question
where do i need to keep ReportGenerator.exe. below line doesnot display the absolute path:
<executable>tools\ReportGenerator\ReportGenerator.exe</executable>
 
#5
Daniel

Daniel

04/10/2013

@Anand:
You have to extract the whole 'CodeCoverage.7z' to 'C:\temp'.
Therefore ReportGenerator.exe is located at 'C:\temp\CodeCoverage\tools\ReportGenerator\ReportGenerator.exe