Configuring code coverage indicators

The default code coverage shown in the Package Explorer, Java™ editor, and views is configurable.

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:

  1. Click Window > Preferences, and click Java > Code Coverage:

    Code Coverage Preference

  2. To enable or disable label decorations, click the Label Decorations link at the top of the preferences page.
  3. In the Label Decorations window, select or clear the Code Coverage Statistics check box, and click Apply.
  4. 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.
  5. Expand Code Coverage in the Colors and Fonts window.
  6. Click the element color you want to change, and then click the colored button on the right side of the window.
  7. In the palette, select the color you want, and click Apply, or click Reset to restore the defaults.
  8. 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.
  9. Select the font you want from the list, and click OK. Click Apply, or click Reset to restore the defaults.

    Coverage Fonts

  10. 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:

    Code Coverage Indicators

    Therefore, the Package Explorer and views show only block code coverage:
    Block Decorations
    Instead, if both block and method coverage indicators are selected, the Package Explorer shows method coverage before block coverage:
    Block and Method Indicators

    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).

  11. 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:
    Coverage Regions
  12. 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.
  13. 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.

Feedback