Monday, May 26, 2014

Selenium in Sonar code coverage metrics


  • 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


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 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.

1 comment:

  1. Hi buddy My name is Ashwani.
    i am looking for jacoco implemention (offline). I am using tomcat 7 and java 8.
    I am struggling to instrument classes and to get the operation dump and report for the same .
    Could you please help me.