Viewing code coverage

Code Coverage information is available in the Coverage Statistics view. Here is a scenario which aims to identify which methods have not been executed and on which class test effort should be concentrated.
In order to turn this feature on, select the profiling option Collect Method Coverage information. Note that unloaded classes are not shown. The Coverage Statistics view looks like this:

Picture of the Coverage Statistics view

This view shows coverage information of the different packages, classes and methods. The display mode can be changed to class mode or method mode using the Coverage Statistics modes toolbar:

Picture of the Coverage Statistics modes toolbar

Package mode is the default one.
Take a look at the % Methods Hit given for the Summary line (right click, select Choose Columns, then set this column to be visible if it is not). The packages (or classes or methods, depending on the current mode) are sorted by name. This information is also available at class level. Develop the package and class node (for example Instrument class here) which is not fully exercised (% Method Hit is not 100%). Now the methods that are not been called in this run appear:

Picture of the methods missed in the Coverage Statistics view

For example, the getNbDigits() method of class Instrument has not been reached. You can open its source code in the source editor by clicking on the Open Source button in the toolbar or by using the pop-up menu.
Switch to the method mode by clicking on the Method toolbar button.
Now sort the items clicking on the Method missed column title. The column title is now marked <Method missed and the methods are sorted showing first all the unexercised ones and then all the called ones:

Picture of the methods missed first in the Coverage statistics view


Now switch to class mode by clicking the Class toolbar button and sort the classes by % Method Hit.

Picture of the classes sorted by % methods hit in the Coverage Statistics view

The Manometer class is fully exercised. All its methods have been called at least once. In the same time, Instrument is the class on which test efforts could be focused.

Related concepts
Coverage Statistics
Overview of the Profiling tool

Related tasks
Profiling an application
Launching or attaching a Java process

 
 

>