Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

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="/path/to/homecoverage/kojodump/jackjacoco.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 - There exist ant tasks in the jacoco distribution that can be used were using java agent creates problems.

Debugging - Code coverage dumps can be inspected by passing the dump file as an argument to ExecDump.java found in the examples folder in the jacoco distribution. 

References

- [measuring code coverage for integration tests using sonar|http://www.sonarsource.org/measure-code-coverage-by-integration-tests-with-sonar/]

- [Java agent|http://download.oracle.com/javase/6/docs/api/java/lang/instrument/package-summary.html]

- [Jacoco|http://www.eclemma.org/jacoco]