Code coverage of unit testing is provided using Cobertura for Maven, and using Emma for Eclipse. Although there is an Eclipse plugin for Cobertura, it has not been maintained and no longer runs on the latest versions of Eclipse. Conversely, although there is a Maven plugin for Emma, the Cobertura plugin gives reports that are more easily understood.
The corporate POM (see Part IV, “Building and Deploying the Corporate Artifacts”) automatically includes the Maven Cobertura plugin:
<!-- quality checks: pmd --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.3</version> <inherited>true</inherited> </plugin>
As for Checkstyle and PMD, this plugin is not bound to any
Maven lifecycle phase, and is not intended to be run other than as a
report within mvn site
. For more immediate
feedback, use the Emma Eclipse plugin, below.
The EclEmma Eclipse plugin offers transparent code coverage directly within the Eclipse IDE. Rather than run the tests using Run > Run As > JUnit Test, instead use Coverage > Coverage As > JUnit Test. This will instrument the code and then provide a coverage view and highlights in the editor to show which code has been exercised.
The coverage view looks like:
The highlighted editor looks like:
Use the menu item on the Coverage View to select between manage the history of coverage runs (selecting none / deleting all removes the highlights on the editor).
To change what code is instrumented, use Coverage > Coverage ... :