jenkins the definitive guide

(Jeff_L) #1

the number of times a given line was executed. Finally, yellow shading in the margin is used to indicate
insufficient conditional coverage (for example, an if statement that was only tested with one outcome).


6.6.2. Measuring Code Coverage with Clover


Clover is an excellent commercial code coverage tool from Atlassian^4. Clover works well for projects
using Ant, Maven, and even Grails. The configuration and use of Clover is well documented on the
Atlassian website, so we won’t describe these aspects in detail. However, to give some context, here is
what a typically Maven 2 configuration of Clover for use with Jenkins would look like:


<build>
...
<plugins>
...
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>3.0.4</version>
<configuration>
<includesTestSourceRoots>false</includesTestSourceRoots>
<generateXml>true</generateXml>
</configuration>
</plugin>
</plugins>
</build>
...

This will generate both an HTML and XML coverage report, including aggregated data if the Maven
project contains multiple modules.


To integrate Clover into Jenkins, you need to install the Jenkins Clover plugin in the usual manner using
the Plugin Manager screen. Once you have restarted Jenkins, you will be able to integrate Clover code
coverage into your builds.


Running Clover on your project is a multistep project: you instrument your application code, run your
tests, aggregate the test data (for multimodule Maven projects) and generate the HTML and XML
reports. Since this can be a fairly slow operation, you typically run it as part of a separate build job, and
not with your normal tests. You can do this as follows:


$ clover2:setup test clover2:aggregate clover2:clover

Next, you need to set up the Clover reporting in Jenkins. Tick the Publish Clover Coverage Report
checkbox to set this up. The configuration is similar to that of Cobertura—you need to provide the path
to the Clover HTML report directory, and to the XML report file, and you can also define threshold
values for sunny and stormy weather, and for unstable builds (see Figure 6.17, “Configuring Clover
reporting in Jenkins”).


(^4) http://www.atlassian.com/software/clover

Free download pdf