This page contains all user documentation for Clover-for-IDEA. Click a heading in the table below to jump to that section.
このページの内容
概要
The Clover IDEA Plugin allows you to instrument your Java code easily from within the IntelliJ IDEA Java IDE, and then view your coverage results inside IDEA.
Screenshot: Clover for IDEA Plugin
まずはじめに
This getting started guide will take you through the steps required to generate Clover coverage for your project.
- Ensure that you have added the clover plugin jar to your project library path.
- Enable Clover, by selecting the 'Enable Clover' check box in the "File | Settings | Project | Clover" interface.
- Turn on clover instrumentation by selecting the toolbar item.
- Rebuild your project using any of the build mechanisms provided by IDEA.
- Run your project by running the unit tests or some other means.
- Refresh the latest coverage data by clicking the toolbar item.
- Highlight coverage in the source code editor by selecting the toolbar item.
Available highlighting options:
highlight covered code (in green) and code with no coverage (in red),
only highlight code with no coverage,
turn code coverage highlighting off. - When option is selected only coverage from passed unit tests contributes to the coverage percentage.
- View the TreeMap report for current project using button.
- View the Cloud report for current project using button.
Viewing Coverage Results
Clover will record the code coverage information each time you run your application or a unit-test. This coverage information is available for viewing using IDEA.
The coverage information can be browsed using the Clover Tool Window. The upper portion of the tool window contains a project class browser with inline coverage information:
Screenshot: Clover Coverage Window
The tool bar at the top of the browser contains the following buttons:
- Flatten Packages. With this selected, only concrete packages are shown in the browser.
- Autoscroll to Source. With this selected, a single click on a class in the browser will load the corresponding source file in an editor pane, with coverage info overlaid.
- Autoscroll from Source. With this selected, the coverage browser will track the currently active source file in the editor pane.
- Always view package in the Cloud report. When this is selected the Cloud view will automatically show a package selected in this tree.
- Show Coverage Summary. With this selected, the Coverage metrics (see below) will be visible.
- Generate Report. Launches a dialog to create a coverage report in HTML, XML or PDF format.
- Cloud report for selected package. Opens Cloud report for selected package.
- Refresh. Reloads coverage data.
- Clean Coverage. Cleans gathered coverage data without deleting the instrumentation database.
- Delete. Delete the current coverage database.
- Set Context Filter. Launches a dialog to set the context filter.
- Set Coverage Scope. Choose which classes should be included in the Clover Coverage View - only application classes, only test classes or all classes.
Screenshot: Setting Context Filters
The lower portion of the Tool Window contains various Metrics for the currently selected node in the browser:
Screenshot: Clover Tool Window Summary
In addition, the plugin can annotate the Java code with the coverage information. This can be turned on by pressing the Show Coverage toolbar button.
Screenshot: Annotated Java Code
If you do not have "Auto Coverage Refresh" enabled, you will need to press the Refresh Button in the Main Toolbar or the Clover Tool Window to see the updated coverage information.
If a source file has changed since a Clover build, then a warning will be displayed alerting you to fact that the inline coverage information may not be accurate. The coverage highlighting will be yellow, rather than the red shown above.
Test Run Explorer
The Test Run Explorer displays recently run tests in your Clover-instrumented project.
The upper panel displays test cases as a flat list ( ), grouped by package ( ) or by source root folder ( ).
The lower panel displays classes and methods covered by the testcase selected in the upper panel. Two metrics are displayed for each class and method:
- Contributed Coverage indicates the percentage of statements that have been covered by selected testcase,
- Unique Coverage indicates the percentage of statements that have been covered by selected testcase only.
Screenshot: Test Run Explorer
Unique Actions in Test Run Explorer
- / / : Click to choose test cases layout.
- : Toggle calculating test coverage to display in the upper panel. If enabled, the plugin will provide information about given test contribution to the selected target scope (see below). Note that enabling this option seriously slows down the Clover database refresh.
- Target scope : Only tests touching selected scope would be shown.
- All tests: All recorded tests in the project,
- File tests: All tests touching the currently displayed file,
- Class / Method / Statement at cursor: All tests involving the class, method or statement under the cursor, respectively.
Select In -> Clover (Alt-F1 menu)
It is possible to view currently selected element in Clover using the Alt-F1 menu.
If the cursor is inside a recognized test case, it would be displayed in Test Runs Explorer, listing methods touched by the test in the lower panel.
Otherwise the element under cursor is displayed in the Coverage view.
Configuration Options
Compilation Options
Configuration options for Clover are accessible on the Clover panel of the Project Properties dialog. The first Tab on this panel provides compilation options:
Screenshot: Clover for IDEA Compilation Options
Initstring
This section controls where the Clover coverage database will be stored. Select 'Automatic' to have Clover manage this location for you (relative to your project directory). Select 'User Specified' to nominate the path to the Clover coverage database. This is useful if you want to use the plugin in conjunction with an Ant build that already sets the location of the Clover coverage database.
Flush Policy
The Flush Policy controls how Clover writes coverage data to disk at runtime. See Flush Policies.
Instrumentation
Allows you to specify a comma separated list of set of Ant Patternsets that describe which files to include and exclude in instrumentation. These options are the same as those described in the <clover-setup> task. You can also specify whether source in test folders should be also instrumented.
Rebuild Policy
The Clover database becomes obsolete after certain operations (such as toggling Build with Clover). The Rebuild Policy setting allows defining the plugin's behavior in the case of such an event.
- Ask: The plugin will show a dialog window asking for confirmation.
- Rebuild Immediately: The plugin will rebuild the project automatically, without asking the user.
- Never Rebuild Automatically: The plugin will neither rebuild nor display a dialog — with this setting the user is responsible for rebuilding the project manually.
View Options
The second Tab on the configuration panel provides view options;
Screenshot: Clover for IDEA View Options
Refresh Policy
The Refresh Policy controls how the Clover Plugin monitors the Coverage Database for new data.
"Manual" means that you have to click button to refresh the coverage data.
"Automatic" means that the Clover Plugin will refresh the database on:
- project open,
- finished compilation,
- termination of unit test or application run.
"Periodically" means that the Clover Plugin will periodically check for new coverage data for you.
一般
Allows you to customize where coverage data is displayed within the IntelliJ IDE. Gutter marks appear in the left hand gutter of the Java Source Editor. Source highlights appear directly over your source code. Shortcut marks appear in the right hand gutter and allow you to navigate directly to uncovered regions of code.
Span
See Using Spans.
Source Highlighting
Allows you to fine tune the colours used Clover in its coverage reporting. The 'highlight colour' for each item is used for Source Highlights and the 'stripe colour' for each item is used for Gutter and Shortcut marks.
Filter Options
The third Tab on the configuration panel provides filter options;
Screenshot: Clover for IDEA Filter Options
Built-in Context Filters
Allows you to specify contexts to ignore when viewing coverage information. For example, selecting the finally body context will remove 'finally' block bodies ('block' syntatic constructs in the Java language) from the reported coverage. For more information, see Coverage Contexts in the Clover Core documentation.
Custom Contexts
This allow you to define custom contexts to ignore when viewing coverage information.
Working with regexp filters:
- Use , or to Create, Delete or Copy respectively the selected filter.
- All new and edited regexp filters will be shown in 'blue', indicating that they are currently unavailable.
- To make a new/edited filter active, you need to delete the existing coverage database using the button and rebuild your project/module.
See Coverage Contexts for more information.
Example: Creating a regexp context filter
For the sake of this example, let us assume that we want to remove all private methods from the coverage reports. How would we go about this?
- Open the configuration panel "Settings | Clover | Filters".
- Select to create a new Regexp Context Filter.
- Set the name to private.
- Since we are creating this filter to filter private 'methods', specify the Method type.
- We now need to define regular expression that will match all private method signatures. That is, a regexp that will match any method with the private modifier. An example of such a regexp is (.* )?private .*. Enter this regexp in the regexp field.
- You will notice that the name of this new filter appears in blue. Blue is used to indicate that the filter is either new or recently edited and therefore 'unavailable'. To make this new filter available, select from the Main Toolbar and recompile your project. Once active, you will notice the private filter appear in the Context Filter Dialog. You will now be able to filter private methods out of your Clover coverage calulations and reports.



































