Introduction
Cobertura is a code coverage tool typically used in conjunction with unit test tools such as JUnit. It provides an analysis of how much of your code was "covered" by the tests.
Many of the integrations listed on this site are of the form where a results xml file is generate and merged into the build log. Then, using XSLT, we can construct some sort of report that is displayed in the cruisecontrol console. Unfortunately there are tools like Cobertura which generate their own html output (a significant amount of their value is in the formatting work they do after the analysis). So, we need to copy those results to somewhere and make them available. This guide provides one way to do that - no doubt there are others (see for instance listing 9 here).
These instructions show you how to arrange for the output to be copied as an "artifact" that is stored as a persistent result of the build, and then how to arrange for that artifact to be published within the cruisecontrol console.
Step 1 - Add Cobertura to your build
For information on adding Cobertura to your Ant build, please refer to the Cobertura website.
Be sure to use an output directory which can later be published as an artifact by the CruiseControl process.
Step 2 - Publish as an artifact
Add a publish line to your project configuration in cruise control. This should copy the entire coberture analysis output (set of html files) into the project artifacts area.
<publishers>
<artifactspublisher
dir="${BuildRoot}\BuildResults\Coverage" subdirectory="cobertura"
dest="artifacts/${project.name}" />
</publishers>
where :
dir is the directory that your build outputs the Cobertura report
subdirectory is the a sub directory of the dest directory parameter directory where the files will be copied to
dest is the parent directory of the destination directory identified by a unique Cruisecontrol timestamp, e.g., artifacts/MyProject/20071105122601/cobertura
Step 4 - Add a new tab in main.jsp
In the CruiseControl webapps directory, there is a file called main.jsp which we need to edit.
Locate the tabsheet element and add a new entry as shown below.
.
.
.
<cruisecontrol:tabsheet>
<tr>
<td bgcolor="white" >
<cruisecontrol:tab name="buildResults" label="Build Results" >
<%@ include file="buildresults.jsp" %>
</cruisecontrol:tab>
<cruisecontrol:tab name="Cobertura" label="Cobertura" >
<%@ include file="cobertura-coverage.jsp" %>
</cruisecontrol:tab>
.
.
.
Step 5 - Create cobertura-coverage.jsp
In the same directory as main.jsp, create a new jsp called cobertura-coverage.jsp (or, call it whatever you want and change the matching name in main.jsp).
<%@ taglib uri="/WEB-INF/cruisecontrol-jsp11.tld" prefix="cruisecontrol"%>
<p>
<cruisecontrol:artifactsLink>
<iframe name="CoberturaFrame" id="cloverFrame" style="width:95%; height:700;"
marginheight="10" frameborder="0" marginwidth="10"
src="<%= artifacts_url %>/cobertura/index.html" width="600"></iframe>
</cruisecontrol:artifactsLink>
</p>
Here, the path /cobertura/index.html matches the directory structure specified in the artifactspublisher seciton of the config.xml (see. It is relative to the root directory containing all the published artifacts from this build.
Complete
That should be it, run a build and then you should be able to view the entire set of results through the cruisecontrol console afterwards.