I have a Maven project with 4 modules - 3 of them contain code and some tests (testing equals and hashcode of the classes) whereas the 4th module is for testing the 3 other modules.
Now I want to run the cobertura code coverage tool to get an overview which classes are well tested and which are not. I did some investigations on that topic and it seems that cobertura is not aware of generating the right code coverage percentages and line coverages, if some sources which are tested are located within other modules.
I have read over some links like SeamTestCoverageWithCobertura and Using the plugin Coverage within a multi-module Maven 2 but there has to be an out of the box solution. Can anybody report some new directions on this topic? Or are there bether tools like cobertura? I've stumbled upon emma but this tool does not offer line coverage...
According to MCOBERTURA-65, the maven cobertura plugin still doesn't know how to aggregate reports of sub-modules into a consolidated one. Some work has been done to implement a
merge
target on the maven cobertura plugin (see MCOBERTURA-33) but this code hasn't been included in the plugin yet. I didn't test the patch myself and can't say if it's worth a try.In consequence, lots of people indeed suggest to use the maven dashboard plugin but I'd personally stay far away from it as it isn't very satisfying on the long term and I faced lots of issues with it (technical problems, lost of history,...). Instead, I warmly recommend Sonar. Have a look at Nemo, a public instance of the last version of Sonar, for a live demo of this tool. See for example the Commons Digester project and the drill down of code coverage.
I could implement something quite similar to what you need thanks to this answer: Maven - add dependency on artifact source
I just added
<classifier>sources</classifier>
and cobertura includes classes from dependencies as well.Regards.
Thomas Sundberg offers an interesting solution in which instrumentation and test reporting is done via
ant
, but all testing and dependency management viamvn
.Check Here: thomassundberg wordpress
It means that you have to execute the commands below at the parent level in this order:
Integrating these steps into
sonar
is described by Martijn Stelinga.test-coverage-in-multi-module-projects
We don't have sonar here and right now, we cant install it. So i had to find a workaround and got one. This solution works with a simple
mvn clean install -DrunCobertura=true
in a multi module project. You only need to add this profile to yoursuper pom.xml
of your project, define theworking.dir
property and it should work.What does it do:
1.
@process-classes
-Instrument the compiled classes of the module.2.
@generate-test-sources
-Merges the.ser
file from previous modules with the created one of this module to get the complete code coverage.3.
@test
-Creates the code coverage report. Should be called in the last module, but due to the fact that the last module can change, i call it always and the previous reports will be overwritten. If you use the report inxml
format (for Jenkins) it's fast, so it doesn't matter.As of version 2.6, there is an aggregate option that can be set to true in the parent pom:
There are a few plugins that aggregate Cobertura (and other) reports. Check out the sonar and XRadar plugins. There is also the dashboard plugin, but it is a bit clunky.
FWIW Emma does do line coverage.