Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

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:

Enjoy!

Monday, May 26, 2014

Selenium in Sonar code coverage metrics

Goal

  • Run Selenium GUI tests as part of the build on Jenkins.
  • Collect code usage data to be able to report code coverage on Sonar.

Project Layout

  • Cloudex-parent
    • Core module - services, daos
    • GUI module - for instance Wicket web GUI
    • Test module - Selenium integration tests

Configuration

There are two relevant parts of Maven config - parent POM which defines JaCoCo offline instrumentation and the test POM which covers deployment to embedded Tomcat and running.

parent pom


Test POM

Just few more points:
  • The config module contains build folder with /lib folder with the configuration which needs to be in Tomcat.
  • We need to include jacoco-agent.properties file in the /lib folder from the previous point. It should contain at least a single line: destfile=${sonar.jacoco.itReportPath} (see offline instrumentation).
  • Selenium tests which should run are defined in the testng.xml.
  • We have a dedicated database on external server which is migrated and against which runs the deployed application.
  • The tests run in Firefox on a headless system (Jenkins master) thanks to Xvfb (X virtual frame buffer), so the Jenkins server must have Firefox and Xvfb installed.