jenkins the definitive guide

(Jeff_L) #1

sense if you are also generating other code quality metrics and reports at the same time. If you want to
do this using Maven 2, you need to also include the Maven Cobertura plugin in the reporting section,
as shown here:


<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>
</project>

Now the coverage data will be generated when you generate the Maven site for this project:


$ mvn site

If your Maven project contains modules (as is common practice for larger Maven projects), you just need
to set up the Cobertura configuration in a parent pom.xml file—test coverage metrics and reports will
be generated separately for each module. If you use the aggregate configuration option, the Maven
Cobertura plugin will also generate a high-level report combining coverage data from all of the modules.
However, whether you use this option or not, the Jenkins Cobertura plugin will take coverage data from
several files and combine them into a single aggregate report.


At the time of writing, there is a limitation with the Maven Cobertura plugin—code coverage will only
be recorded for tests executed during the test life cycle phase, and not for tests executed during the
integration-test phase. This can be an issue if you are using this phase to run integration or web
tests that require a fully packaged and deployed application—in this case, coverage from tests that are
only performed during the integration test phase will not be counted in the Cobertura code coverage
metrics.


6.6.1.2. Integrating Cobertura with Ant


Integrating Cobertura into your Ant build is more complicated than doing so in Maven. However it does
give you a finer control over what classes are instrumented, and when coverage is measured.


Cobertura comes bundled with an Ant task that you can use to integrate Cobertura into your Ant builds.
You will need to download the latest Cobertura distribution, and unzip it somewhere on your hard disk.

Free download pdf