Cobertura is a free Java tool that calculates the percentage of code
accessed by tests. It can be used to identify which parts of your
Java program are lacking test coverage. It is based on jcoverage, but more actively developed.
I will talk about the maven cobertura plugin,
after releasing the first two versions (7/11 and 7/21) you can have
cool reports about test coverage and the ability to see all the classes
that don’t meet your minimum coverage criteria, both at line and branch
level.
The first report about code coverage is pretty similar to the one provided by Clover, but the second one
makes the difference, not provided by clover and in fact neither by
cobertura ant tasks, just the maven plugin. Another interested feature
to be used for instance in conjuction with a continuos integration tool
as CruiseControl is the option to make the build fail if any of the
classes test coverage fails below a threshold you can set. AFAIK clover
only allows to fail the test if the overall code coverage doesn’t meet
the requirements, not class by class, which is very convenient.
To use it in your maven projects you can add the dependency to the plugin
<dependency>
<groupId>maven-plugins</groupId>
<artifactId>maven-cobertura-plugin</artifactId>
<version>1.1</version>
<type>plugin</type>
</dependency>
and the report
<report>maven-cobertura-plugin</report>
I hope you find it useful.
[Trackback] Carlos Sanchez has created a Maven Plugin for the code coverage tool Corbertura . This is very nice because now there is a powerful open source alternative to Clover which is a good project but unfortunately not available for free and for JCover…
[Trackback] I’ve replaced jcoverage/gpl by cobertura thanks to the recently released Maven plugin.
Result for the coverage part is neat. Html produced is bug free, layout and display is clear, it even include a nice help for column header. It’s easy to say
Could you please send me your pom.xml for reference? Thanks!
This tip is only for maven 1.x
Your work is great. Happy New Year! And Marry Cristmass!
The few lines to invoke the plugin are just what i needed. I have tried for hours to invoke Cobertura, but without success. Finally I found this post. These lines should be on the frontpage of the maven-coberura-plugin site.