Wednesday, November 23, 2005

EMMA - Code Coverage

A free Java Code Coverage Tool

Recently I have used EMMA and I have been completely satisfied with the results it provided. Before I started working, I have also tried out the Borland code coverage tool from the Optimizeit enterprise suite, but the tools differ from each other, as well as the reports which are generated. I find the EMMA report easier to overview, and more user friendly. Plus it is free. I guess it can take a little time until you get familiar with it, but it is worth the effort.

"EMMA distinguishes itself from other tools by going after a unique feature combination: support for large-scale enterprise software development while keeping individual developer's work fast and iterative ... " as the "Borland Optimizeit Code Coverage gives developers the confidence that their code is ready to deploy when performance checks are run during development". (Sources: EMMA, Optimizeit.)

Here you can check out two sample coverage reports:
Both tools have the advantage that they can be integrated with Eclipse IDE. Though EMMA does not have a plugin for Eclipse, the way to use it from Eclipse is adding EMMA tasks to your ANT build. You can read the step by step instructions here. Like this you are enabled to run an application from ANT "so that coverage instrumentation is performed on-the-fly, as the classes are loaded by the JVM", and then the same process is repeated by breaking it into distinct instrumentation/execution/reporting steps. What I particularly like about EMMA is the option of separating instrumentation and execution (Offline mode). This is useful when there is a necessity of collecting and merging coverage data from multiple execution runs and multiple JVM processes.

Lance Finney has found EMMA to be a winner-tool: "Emma uses an interesting approach to defining coverage that often results in lines being only partially covered. For example, lines with ternary operators with only one branch executed will show as partially executed".

Technorati tags: code coverage, Emma code coverage, Ant.