Friday, April 8, 2016

SonarQube Integration Test Coverage with Cargo plugin

I already described how to get integration test coverage into your Sonar when your application runs on Tomcat here. I came to a project that uses Cargo Maven plugin to deploy the app on a Tomcat for integration tests. I wanted to see how much these tests actually cover. The answer to that turned out to be 'not that much really' but I'd like to share with you how to adjust configuration of the Cargo Maven plugin to make it work with Sonar.

Let's go.

Sonar properties

So in our case we have a multimodule Maven project. In order to collect usage over the project just set following sonar properties:

The default configuration puts jacoco.exec in the target of a module. We want to collect code coverage over several modules (including cases when code from one module calls code from another module) so we have to put Jacoco output files up the folder hierarchy and configure Jacoco plugin to append to these files.

In order to collect integration test coverage from deployed app we configure the Jacoco offline instrumentation to get a WAR file with instrumented classes. Jacoco agent deployed along with the war can then collect coverage data to specified file.

Jacoco Offline Instrumentation

The Sonar profile which configures offline instrumentation in the main pom looks pretty much the same as in the previous blog post:

Cargo plugin

Cargo plugin needs to deploy jacoco agent jar along with the application WAR. It also needs to set system property for jacoco-agent.destfile so that the agent can write collected coverage data to it.

Then just run:



  1. Hi I liked this post and i have the similar requirement for my project to run integration tests with cargo and jacoco offline instrumentation. Any git hub link for that would be really helpful.

    Project info:
    I have multi module project where one of the module is having aspectj and other modules are non aspectJ. I read somewhere that jacoco coverage is getting impact by aspjecj and solution to that is use offline instrumentation.
    I am trying the same. Can you help me in that?

  2. also here you are talking about integration tests but i see you are having prepare-agent for pre-unit test phase.

  3. do i need to run unit tests inorder to get integration coverage for multimodule project