Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Background

Sonar currently reports on the code coverage of unit tests only using the Emma code coverage tool. It is however

desirable to have code coverage for integration and acceptance tests as well. This will help us measure our progress

towards automating all manual tests and improve the efficiency of our test base. 

Jacoco

Jacoco is a code coverage tool that uses a different approach from Emma in to obtain code coverage data. Basically, 

it does bytecode instrumentation on-the-fly using the java agent technology. It works by inserting probes (additional instructions

that record the fact that they have been executed) into the code base accessible to the virtual machine. It is therefore important

to define inclusions and exclusions to restrict jacoco to mifos code.

Getting the tools

Download jacoco 

Download sonar jacoco plugin 

Download sonar 

Insert the jacoco plugin in the $SONAR_HOME/extensions/plugin  directory

Doing the business (getting coverage report - integration tests)

  • Modify the pom.xml in $MIFOS_HOME/applicaton directory by adding the following line to maven-surefire-plugin configuration element
Code Block

<argLine>-javaagent:${jacoco.agent.path}=destfile=${jacoco.file.path},includes=org.mifos.*,excludes=*_javaassist_*</argLine>

* 
  • Run

...

  • acceptance

...

  • tests,

...

  • supply

...

  • the

...

  • arguments

...

  • defined

...

  • in

...

  • the

...

  • maven-surefire-plugin

...

  • above
Code Block
mvn \-Djacoco.agent.path="/path/to/jacoco/library/jacocoagent.jar" \-Djacoco.file.path="/path/to/coverage/dump/jacoco.exec" clean install

* 
  • Run

...

  • sonar

...

  • analysis

...

  • on

...

  • entire

...

  • project

...

Code Block
mvn \-Dsonar.jacoco.itReportPath="/home/kojo/jack.exec" sonar:sonar \-Dsonar.dynamicAnalysis


 consider using \

                 consider using -Dsonar.dynamicAnalysis=reuseReports

...

 to considerably reduce the time taken for code analysis

  • Go to sonar web interface and click on 'configure widgets' to add IT coverage widget 

Miscellaneous 

Jacoco Ant tasks

References

- Java agent

- Jacoco