I have a multi-module Maven setup with Java code.
My unit tests, in one of the modules, exercise code in multiple modules. Naturally, the modules have inter-dependencies, and code in all relevant modules is compiled as needed in advance of test execution.
So: How can I get a report on the coverage of the entire codebase?
Note: I am not asking how to combine the results of coverage for tests in multiple modules. I am asking how to get coverage for tests in a single module using instrumented code from multiple modules. Anyone interested in the former might refer to these other questions, and the recommendations by Crowne for Maven Dashboard and Sonar.
I succeeded in getting a full coverage report using pure Ant. [EDIT:] I instrumented all jars from the development-runtime directory into a temporary directory; prepended the temporary directory to the classpath; then ran tests from Ant with batch-test.
Ant can be run from Maven, but the challenge here is seamless integration (i.e., feeding all the classpath and sourcepath elements from Maven to Ant automatically), which is why I did not use Maven's facilities for this purpose.
There are also other questions about integration tests. However, by default, each project's report by default only reports coverage on code in the same project, whereas my tests exercise code in multiple projects.
This article in Spanish might be relevant. Here is another Seam-specific article.
I doubt if would be possible since the coverage information is obtained by cobertura/emma by instrumenting the compiled classes. While this would work for classes in the specified project, it is doubtful if these tools will instrument dependant libraries.
A look at the maven cobertura plugin usage also does not seem to indicate any such possibility.
Never tried, but this may be a way to accomplish it:
mvn site
See cobertura documentation on how to manually invoke cobertura to instrument external JAR files in-place:
The
pom.xml
's build plugins may look like this - you may want to add a profile or use classifiers to distinguish between the final jar file and the instrumented jar file if you don't want to overwrite them in your local repo. Then, in the tests module, you just need to define the dependencies to your other modules using the classifiers.Generally, reports pertain to their specific module, however they can be aggregated,
two approaches are:
I would recommend that you try using sonar to do the report aggregation for you.
See their public instance "nemo", to see the impressive capabilities that are offered.
I found this pretty straightforward (although I did it a while ago, and may be rusty with details...
My core project contains all of the modules. I use Cobertura to measure my test coverage. I am using Hudson as a Continuous Integration engine, and have the Cobertura plugin for Hudson.
It has been working a treat for a while now.
Good Luck !
This recent blog post by Thomas Sundberg contains a method that partially solves the issue by using ant for the cobertura calls, instead of using the maven cobertura plugin.
It relies on the following basic approach with specialised pom.xml and build.xml files :
Start with a typical maven compile on the parent pom, which will compile all classes in the child modules.
Then instrument all of the module classes:
Then call the maven-surefire-plugin called for testing using the instrumented classes, with cobertura as a test dependency
Then use a custom report call to pull in all of the results from different modules:
The key elements of the ant build.xml file are to instrument all modules separately and then to report on all of the modules after merging the results. This function needs to be called for each module in his example:
Then after the testing is complete, the reporting phase first merges all results from all of the different directories are merged into a new .ser file (called sum.ser in his example)
It may be possible to integrate the ant components into maven using the antrun plugin, but I am not familiar enough with the phases/lifecycles to know where to put the different calls.
This is very useful for me, as I write abstract test classes in my api modules and then provide them with an implementation in my lib modules. So far both cobertura and emma have been unable to handle this design so my code coverage is typically 0 or in the single digits.