Overview

The Clover Eclipse Plugin allows you to instrument your Java code easily from within the Eclipse Java IDE, and to view your coverage results inside Eclipse.

Using the plugin

Enabling Clover for your project

Clover can be enabled for any of your Java-based Eclipse projects.

  1. From the Project Explorer view, right click on your Java project.
  2. Select "Clover | Enable on this project". Alternatively you can enable Clover on multiple projects at the same time by selecting "Clover | Enable/Disable on..." and then selecting the projects to enable or disable.
  3. With Clover now enabled, your project will now be automatically rebuilt. If you have upgraded from a previous version of Clover you may need to perform a clean build of all your Clover-enabled projects.
  4. When enabling Clover on a project, the Coverage Explorer, Test Run Explorer and the Test Contributions views will all open automatically.
  5. Select the Coverage Explorer view. This view is designed for horizontal placement but will also work well if placed vertically. You should see your project listed with 0% code coverage.
  6. Select the Test Run Explorer view. The view is designed for horizontal placement but will also work well if placed vertically. As you have not executed any Clover-enabled tests, this view won't tell you anything interesting yet.
  7. Select the Test Contributions View by selecting "Window | Show View | Other..." and selecting Clover > Test Contributions. The view is designed for vertical placement but will also work well if placed horizonally. As you have not executed any Clover-enabled tests, this view won't tell you anything interesting yet.

Screenshot: Enabling Clover in Eclipse

 
 Screenshot: Enabling/Disabling Clover on Multiple Projects

 

The Clover Coverage Explorer

The Coverage Explorer allows you to view and control Clover's instrumentation of your Java projects, and shows you the coverage statistics for each project based on recent test runs or application runs. It is automatically added to the workbench when you enable Clover for your project. If the viewer is closed, you can open it again using "Window | Show View | Other..." and selecting "Clover | Coverage Explorer".

The main tree shows coverage and metrics information for packages, files, class and methods of any Clover-enabled project in your workspace. Clover will auto-detect which classes are your tests and which are your application classes - by using the drop-down box above the tree you can then restrict the coverage tree shown so that you only see coverage for application classes, test classes or both.

Screenshot: Clover Coverage Explorer

Columns

Initially the Coverage Explorer's tree displays the following four columns:

Clover supports 24 standard column types which can be chosen in the Coverage Explorer Column Chooser. The Column Chooser can be summoned by selecting "Columns..." in the Coverage Explorer view menu.

Screenshot: Coverage Explorer Column Chooser


 

Clover-for-Eclipse also lets your define your own custom columns for display within the Coverage Explorer tree. While choosing columns in the Column Chooser dialog, click the "New" button to summon the Custom Column Builder dialog. Custom columns must have a name and a valid Clover expression. Custom columns may be left, center or right justified and the value may be displayed as a decimal value or as a percentage value. Clover expressions can refer to any of the 24 standard columns; these references can be easily inserted into the expression by selecting "Insert..." and choosing the appropriate column name.

Screenshot: Coverage Explorer Custom Column Builder


 

Summary Panel

Summary metrics are displayed alongside the tree for the selected project, package, file, class or method in the tree. The following metrics are provided:

Actions and Menus

The viewer allows the following actions (from the view toolbar, menu or both):

Viewing Coverage Results

The Clover-for-Eclipse plugin shows coverage data in number of ways. Viewing any coverage data, of course, requires that you have executed tests or you have launched your application and it also requires that Clover has detected the change in coverage. On the Clover preferences page, you can change how often Clover looks for new coverage data for your application or tests.

Source Code Annotations 

To view coverage information on a line-by-line basis, Clover adds coloured annotations to your project's Java source code editors.

Screenshot: Clover Source Annotations

The table below explains the meanings of various colours:

Annotation Colour

Meaning

Green

Coverage from passing tests.

Green

Coverage caused incidentally (caused by something other than test methods, e.g. main() methods, test setUp() and tearDown() methods). A different tooltip is presented to show it is incidental.

Squiggly Red Lines

Partial branch coverage (caused when only one part of a branch has been covered).

Yellow

Failed test coverage (where coverage has only been caused by one or more failing tests and no passing tests).

Grey

Filtered out code.

Red

Code with no coverage.

Each coloured source annotation displays a tool tip providing more information about the relevant line or lines. These coverage annotations are added automatically to any opened source files from a Clover-enabled project. For example, if a statement was executed ten times, or a conditional expression was only executed twice in the true case but never in the false case, this information will appear in the tool tip.

If you wish to switch off the source code annotations, you can easily do so by de-selecting the menu / toolbar item "Show Coverage in Editor" on the Coverage Explorer view or Test Run Explorer view. Using an adjacent menu / toolbar item you can also force Clover to only annotate code without coverage, thus only showing the red annotations.

You can also change these colours and effects in Eclipse. To do so, access 'Eclipse Preferences > General > Editors > Text Editors > Annotations'. On this page, see the 'Annotation Types' list and click the settings that begin with 'Clover'.

Screenshot: Clover Source Annotation Settings

Test Run Explorer

The Test Run Explorer view, like several popular plugins such as the JUnit Plugin or TestNG Plugin, lets you explore your recently run tests - showing whether they passed or failed, their duration and any error messages that they generated. Clover-for-Eclipse takes this one step further and allows you to explore the code coverage caused by an individual test, a test class, a package or even your entire project.

After running tests in a Clover-enabled project, select the Test Run Explorer view (or to open it, select Window > Show Views > Other... > Test Run Explorer). On the left-hand side of this view you will see a tree of tests that were run and their containers such as classes, packages, projects etc. On selecting an element on the left-hand side, the right-hand side displays all the application (i.e. non-test) classes that had coverage caused by the selection.

For example, selecting a test method on the left side will cause the right-hand side to show the application classes with code executed (directly or indirectly) by that test method. Selecting a test class or test package will cause the right-hand side to show application classes with code executed by all the test methods contained by the test classes or test package.

The right-hand table displays not only the names of the classes that were partially or fully covered by the test methods, but also the percentage of class' total coverage that is attributable to the test method (the test method's coverage contribution) as well as the percentage of the class' coverage that was attributable only to the selected test method (the test method's unique coverage).

The tree of tests and their containers on the left-hand tree can be presented in three different ways for maximum convenience:

  1. Packages : shows Project > Package > Class > Files > Test Classes > Test Methods
  2. Package Roots: shows Project > Package Root > Package > Class > Files > Test Classes > Test Methods
  3. Test Cases: shows Project > Test Methods (qualified with Test Class names)     

Screenshot: Clover Test Run Explorer

Coverage Cloud Reports

Coverage cloud report are a great way to work out the classes that form major risks (low coverage but high complexity) to your project and its packages, and also to highlight potential quick wins for increasing the overall project or per-package coverage.

The coverage cloud report has two tabs, one tab for the project/package risks cloud and the other for quick wins cloud. Each cloud shows the classes of the project/package enlarged or reduced depending on their significance to the report and clicking on any class name will open the corresponding source file in an editor. At the bottom of the report you can select the target for the clouds - either the entire project or one of the packages within the project - changing this will update the cloud tabs. Where a package is selected and has sub-packages, the checkbox "Include classes from sub-packages" allows you to include or exclude sub-package clouds from the clouds.

The coverage cloud report can be generated by right clicking on your Clover-enabled project in the Coverage Explorer view or Test Run Explorer view and selecting Generate Coverage Cloud.

Screenshot: Clover Coverage Cloud Report

 Coverage Treemap Reports

The coverage treemap report allows simultaneous comparison of classes and package by complexity and by code coverage. The treemap is divided by package (labelled) and then further divided by class (unlabelled). The size of the package or class indicates its complexity (larger squares indicate great complexity, while smaller squares indicate less complexity). Colours indicate the level of coverage, as follows:

The percentage shown in the yellow box is the code coverage for the class currently under the mouse.

Right clicking on a package area and selecting the magnify option will then focus the treemap on the package's classes. Right clicking again and selecting the demagnify option will re-focus on the project's top level. Double clicking on a class will open the corresponding source file in an editor.

The treemap cloud report can be generated by right clicking on your Clover-enabled project in the Coverage Explorer and selecting Generate Coverage Treemap.

Screenshot: Clover Coverage Treemap Report

Test Contributions

The Test Contributions view shows unit tests and methods that generated coverage for the currently opened and selected Java source file. As you switch between Java source file editors, the top most tree is updated with the test methods that contributed to coverage of this file. Clicking on the any of the tests and their methods will take you to their associated source. Unchecking a test or test method will remove the coverage it provides from the open source file. The bottom tree tracks the test methods that contributed to coverage of the file at the current cursor position.

The Test Contributions view allows you to better understand the relationship between your test code and your application code as you move between Java source files.

Screenshot: Clover Test Contributions

Disabling Clover

In order to track the code coverage of your projects, Clover must insert special code into your programs at compilation time - called instrumentation - to record this coverage. When Clover is enabled on your projects, Clover will automatically perform this task for every file you compile in the project. You can tell Clover not to instrument your projects by right clicking on them in the Coverage Explorer or Test Run Explorer views and deselecting "Compiled with Clover".

If you wish to temporarily disable the red/green code coverage annotations in your Java source editors (but wish to continue using Clover on your projects), you can simple toggle the "Show Coverage in Editor". This setting applies to all Clover-enabled projects in the workspace.

If you want to completely disable Clover support for a project (which will remove it from the three Clover views etc), then right clicking on the project and selecting "Clover | Disable on this Project". If you wish to disable Clover on multiple projects, right click on one of them and select "Clover | Enable/Disable on..." and deselect the projects you wish to disable Clover for.

Configuration options

The Clover Eclipse plugin's configuration can be accessed in two places:

Project Properties - Instrumentation

These options control how Clover instrumentation works when "Compile with Clover" is selected on your project.

Screenshot: Instrumentation Properties

Project Properties - Contexts

Clover's coverage contexts allow you to filter out certain parts of your project's code when considering how much of your code is covered. This is useful when you do not have 100% code coverage yet don't feel the uncovered code is of sufficient importance to invest time to test. See Using Coverage Contexts for an in-depth discussion of contexts and how they are used.

Clover recognises two main types of contexts - block contexts which are pre-defined by Clover, and custom contexts which are defined by you.

Screenshot: Eclipse Project Context Filtering

Project Properties - Source Files

The Source Files tab let you select in detail what exactly should be instrumented. You can select one of the following:

This configuration windows allows you to use Ant-style pattern sets. If there are only certain source files you want instrumented, then by using these Ant-style include and exclude patternsets you can fine-tune how Clover determines whether files are eligible for instrumentation. For example, by using an "Excludes" value of **/remote/*.java you will stop instrumentation of files in the "remote" folder of your project.

Screenshot: Eclipse Project Source File Settings

Project Properties - Test Classes

The Test classes tab lets you select how Clover should look for your tests. You can select from one of the following:

Clover Preferences - General

These options control how Clover works across all projects which have "Compile with Clover" enabled.

Screenshot: Clover Eclipse Preferences

Clover Preferences - License

This option allows you to view and change the license you use with Clover.

Screenshot: Clover License Preferences

FAQ

See the Eclipse Plugin FAQ