How do I generate a Cobertura test coverage report for a site?
Author: Deron Eriksson
Description: This maven tutorial describes how to generate a test coverage report for a site using the Cobertura Maven Plugin.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)
(Continued from page 1)
Now I'll examine the Cobertura Test Coverage report that was generated in the documentation site.
We can see that the layout of the code coverage report looks similar to the framed layout of javadocs. Here, we can see the code coverage report for all packages. We only have one package, com.maventest. The code coverage for the package was 7 of 9 total lines (78%). This means that the unit tests hit 7 of the 9 total lines in our source code.
I drilled into the com.maventest package. We can see that the com.maventest package has two classes in it, App and Howdy. App had 50% coverage (2 of 4 lines were hit), and Howdy had 100% coverage (5 of 5 lines were hit).
I drilled into the Howdy class. Here, we can see that all lines of code in the class were hit. In addition, we can see that the sayHello() method of Howdy actually gets hit twice by our unit tests.
The Cobertura Test Coverage report is a great, visual way of displaying the test coverage of your unit tests in your projects.