Configuring code coverage indicators
About this task
For each Java or plugin project, you can configure the following code coverage elements:
- Label decorations.
- Colors and fonts.
- Code coverage indicators.
- Java editor indicators.
- The number of Java launches cached for code coverage reports.
- Collection options.
You can enable or disable label indicators for covered, partially covered, and uncovered lines in the Package Explorer, Java editor, and views. You can set colors and fonts for the indicators. You can specify which code coverage indicators you want to see in the Package Explorer and views. You can also specify how many Java launches to cache for use in code coverage reports as well as whether to collect code coverage data on default constructors.
To configure your preferences for code coverage:
- Click
- To enable or disable label decorations, click the Label Decorations link at the top of the preferences page.
- In the Label Decorations window, select or clear the Code Coverage Statistics check box, and click Apply.
- To configure the fonts and colors used for code coverage indicators, click the Colors and Fonts link at the top of the Code Coverage preferences page.
- Expand Code Coverage in the Colors and Fonts window.
- Click the element color you want to change, and then click the colored button on the right side of the window.
- In the palette, select the color you want, and click Apply, or click Reset to restore the defaults.
- To configure the fonts used in the Package Explorer and views, click the element font you want to change, for example, the Partially Covered Element Font, and click Change.
- Select the font you want from the list, and click OK.
Click Apply, or click Reset to
restore the defaults.
- In the Code Coverage Preferences page, you can configure the indicators
themselves. Select one or more indicators for coverage of packages,
source files, types (a concrete class or enumeration), and methods,
and then click Apply. If you choose more than
one, the hierarchy is type, method, block, and line, in the order
shown in the box. Please note that the definition of a block is code
(portion of a line, a single line, or multiple lines) that cannot
be branched into or branched out of. All of the code in a block is
executed as a single group of instructions. Blocks are terminated
with a branch in or branch out (for example calling a method, throwing
an exception, or returning).
In the following example, only block indicators are selected:
Therefore, the Package Explorer and views show only block code coverage:Instead, if both block and method coverage indicators are selected, the Package Explorer shows method coverage before block coverage:Note that clearing the Show colored indicators in the views check box will remove the colored decorations from the Package Explorer and views (such as the Outline view) while preserving the display of code coverage percentages (without color).
- In the Java editor box of
the Code Coverage preferences page, select the coverage options you
want for the project, and click Apply. In this
example, partially covered lines are not enabled:
- In the Java Launching box, type the number of launches to cache for code coverage use, and click Apply. Note that this applies only to launches initiated from the workspace. The number of launches you cache has disk space implications.
- To specify whether default constructors are included in the code coverage computations, select Include data on default constructors. By default, the default constructors are included; if a class does not define any constructors, then the compiler generates a default no argument constructor. However, this constructor does not show up in the actual source file. During the program execution if this class is not instantiated then this hidden default constructor is not executed and hence the coverage does not equate to 100% as expected. This behavior can be controlled by this preference.