Code Coverage with TomEE, JaCoCo and SonarQube
Feb 8, 2017 14:53 · 187 words · 1 minute read
Recently we were facing the challenge how to integrate code coverage analysis for functional tests in our continuous delivery process.
We were already using JaCoCo before, but checking on the internet I never found one simple example to start from scratch. So I decided to publish one here.
Despite the documentation is quite heavy, it is actually really simple to integrate code coverage analysis in your environment (in the example we are using a TomEE Container).
Two things are important:
You need to provide the JaCoCo Agent, which you can download here. In the example, we mount the agent from outside into the Docker container. That way, we don’t need to deliver the agent in the production image.
You need to modify the JAVA_OPTS environment variable to tell your server that a Java Agent is running:
JAVA_OPTS=-javaagent:/jacocoagent.jar=output=tcpserver,address=*
Afterwards you can retrieve the JaCoCo Dump with maven with:
mvn jacoco:dump -Djacoco.address=<hostname of your server>
And publish the result to SonarQube, which will do the coverage computation:
mvn sonar:sonar -Dsonar.host.url=http://<hostname of sonarqube>:9000
I hope this little example helps one or the another who is struggeling with the same issues.