Measuring code coverage with EMMA

This page is intended to contain up to date information on how to measure code coverage for the Derby tests with the EMMA tool.

Versions

Running the Derby junit tests instrumented with EMMA has been tested with EMMA version 2.0.5312.

Running EMMA with ant

Ant targets have been created to help measure code coverage with EMMA for the Derby tests written in junit. To use these ant targets you need to download EMMA and place the two jar-files (emma.jar and emma_ant.jar) in the tools/java/ directory in your sandbox. Here they will be found by the Derby build system and the ant targets related to EMMA should work as intended. You can download the latest EMMA jar-files from http://emma.sourceforge.net/downloads.html. You should also download junit.jar and put it at the same place, if you are using ant 1.7 the buildsystem will find it there.

The ant targets use your compiled jars (either sane or insane depending on your properties) and instrument these with EMMA code. If you want the code coverage report to contain source code information, you have to compile Derby with debug=true. The Derby jars have to be built with the buildjars target before using the EMMA targets. The instrumented jars are placed in a separate directory under jars/emma/ and are used to execute the junit tests. The instrumentation process also produces a file named coverage.em with data that EMMA later needs to produce the coverage report, this file is placed in the same directory as the logs from the test.

During the testruns, data on coverage is written to a file named coverage.ec, also located in the directory with the test logs. After the tests are finished, reports are produced using the data located in the coverage.em and coverage.ec files and linked to your source code (if you compiled with debug=true). The reports are named coverage.txt, coverage.xml and coverage.html, and all contain the same information.

Note

EMMA marks a block as covered, only if that block exits normally. Thus if a block terminates due to a thrown exception, it is not marked as covered. http://emma.sourceforge.net/faq.html#q.blockcoverage. So, although coverage report indicates a block of code as uncovered, it might have been invoked.

Ant Targets

ant target

Comments

emma-all

Instruments the Derby jar files with EMMA and runs junit-all automatically setting the classpath to the jar files instrumented with EMMA. When the tests are finished, a code coverage report is produced in three copies (txt, html and xml) in the directory where the test logs are placed.

emma-single

Instruments the Derby jar files with EMMA and runs junit-single automatically setting the classpath to the jar files instrumented with EMMA. When the tests are finished, a code coverage report is produced in three copies (txt, html and xml) in the directory where the test logs are placed. As for the junit-single task the test or suite to execute is selected by setting the system property derby.junit.testclass to the full classname of the test or suite you want to run.

emma-clean

Remove the EMMA-instrumented jar files located at jars/emma/

junit-clean

Remove any folders from previous junit runs (with or without EMMA) through ant targets.

Community measurements

Code coverage numbers and reports produced by community members can be found here: CodeCoverage

CodeCoverageWithEMMA (last edited 2012-07-19 05:48:56 by MohamedNufail)