1. Introduction
This blog shows how to seperate your unit and integration tests in a multi-module maven project whilst providing seperate test coverage results for each.
It builds upon my previous 2 simpler examples using Sonar and Jacoco.
http://johndobie.blogspot.com/2011/06/seperating-maven-unit-integration-tests.html
It's a full example in its own right but I won't go into too much detail on how it works which is already done.
It's a full example in its own right but I won't go into too much detail on how it works which is already done.
The previous examples cover everything in sufficient detail.
The full example can be checked out from google code and run as below.
1.1 Example Structure
We mirror the 2 structures as per the previous blogs with the unit and integration tests seperated.
Because this is a multi-module example, we have also have the top level pom.xml and common-pom.xml.
1.2 Running the Example
The full code is hosted at google code. Use the following commands to check it out and run it.
svn co https://designbycontract.googlecode.com/svn/trunk/multi-module-sonar
cd multi-module-sonar
mvn –Pit,sonar clean sonar
1.3 Results of running the example
- The tests in the standard maven test structure are run during the unit test phase as usual.
- The tests in the \src\integrationtest\java directory are run during the integration test phase.
- The integration test classes are placed in the seperate \target\integrationtest-classes directory
The aggregated jacoco coverage files are placed in the code-coverage directory
Check out the previous blogs to see how the unit and integration tests are run seperately and the code coverage works. This example just builds upon that by using more than one module.





Hi,
ReplyDeleteFirst of all, many thanks for this tutorial (the best on this subject). I'm going to implement this technique on my project but I have 2 questions:
* are the code-coverage/*.exec cleaned at the end of the build and how? Isn't jacoco going to append data to those files when a 2nd "mvn clean sonar" is run?
* is it possible for the jacoco sonar reporting plugin to show number of "it" test run? (same as for "unit" tests)
Thanks again!
Hi, Yeah this currently reports the sum of coverage for all of the modules.
DeleteIt doesn't matter if you append build data more than once, the results are the same so cleaning is not that important. However it would be worth tidying up by deleting at the start of the build.
As for your second question i'm not sure. Sonar 2.12 may do this now.
http://www.sonarsource.org/sonar-2-12-in-screenshots/
Good luck.
Hi, Yeah this currently reports the sum of coverage for all of the modules.
ReplyDeleteIt doesn't matter if you append build data more than once, the results are the same so cleaning is not that important. However it would be worth tidying up by deleting at the start of the build.
As for your second question i'm not sure. Sonar 2.12 may do this now.
http://www.sonarsource.org/sonar-2-12-in-screenshots/
Good luck.