The code coverage refers to a technique for programming technology by which you measure the quality and comprehensiveness of your test suite with a simple metric such as the percentage of classes, methods, lines, etc. that have been successfully been executed during the test suite.
Several tools allow code coverage:
In our case, we will check out the EclEmma plugin.
Introducing the EclEmma plugin
EclEmma is a free Java code coverage tool for the Eclipse IDE, it is a plugin that is combined with JUnit.
When unit tests are launched, the tool will analyze upon the code and will perform a (color) marking upon it. For example, the red color is used to display part of thecode that unit testing does not cover. It is therefore possible to verify a glance the pieces of code that are supported or not.
Source Code Analysis
After running the application or testing unit, the information about the code coverage is automatically available in Eclipse workbench:
Overview: the code coverage lists summaries for projects in java.
The analysis provides figures by line of code, by method, type, etc. as shown in the screenshots below:
Methods coverage range:
Line coverage range:
Source highlighting: The results of the code coverage are also directly visible in the java source code through a color-coded marking. The colors used by default are:
The green color: For fully covered lines.
The yellow color code: to display the partially covered items (unit tests)
The red color: is used to display part of the code that unit testing does not cover.
These colors are set in eclipse:
Menu windows-> preferences-> General-> Editors-> Text Editors -> Annotations
As for the annotations, you should get: "full coverage range," "partial coverage range" and "without coverage range" with the choice of corresponding colors.
Import and Export Features
EclEmma is primarily intended for testing and analysis within the Eclipse workbench, but it also provides a mechanism for import/export.
Import code coverage report: Possibility to import a session in the *.ec format.
Export code coverage report: The data may be exported in XML or HTML format.
This document entitled « EclEmma Plugin » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.