4. Scope of instrumentation in Eclipse

 

Clover provides many ways to fine-tune instrumentation scope, which gives you an ability to concentrate your work on the most important code.

 

Enabling and disabling Clover for selected projects

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

 

Enabling and disabling instrumentation for Clover-enabled projects

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" option or

  • selecting them in the Coverage Explorer or Test Run Explorer views and clicking "Toggle whether Clover Instrumentation..." button

 

Excluding and including packages

Right click on a package in Package Explorer view, choose "Clover > Include/Exclude <package name>" from context menu.

 

Excluding and including files

Right click on a file in Package Explorer view, choose "Clover > Include/Exclude <file name>" from context menu.

 

Excluding certain blocks of code

Right click on a project in Package Explorer view, choose "Properties" from context menu, next "Clover > Instrumentation" tab.

In the Standard Coverage Context Filters you can choose Java language constructs or coding patterns to be excluded. The most interesting are:

  • assert statements
  • catch body
  • finally body
  • private methods (all methods having private keyword)
  • property methods (all methods having name like getXyz() / setXyz() / isXyz(), being public and having no arguments for isXyz/getXyz)

 

Excluding methods and statements matching regular expression

Right click on a project in Package Explorer view, choose "Properties" from context menu, next "Clover > Instrumentation" tab.

In the Custom Coverage Context Filters you can define regular expressions for method signatures and statements.

 

Excluding arbitrary lines of code

Put "///CLOVER:OFF" and "///CLOVER:ON" in source code (note that three slashes are used) to exclude given sections.

 

Setting instrumentation detail level

Left click on a project in Coverage Explorer view. A pop-up will show with "Instrument and compile at" having two options:

  • statement level - it is a recommended setting as it gives the most accurate information about code coverage; Clover will record information about: method calls, statement calls and whether given branch was evaluated to true/false.
  • method level - it records only whether given method was called or not; this option can be useful for very large projects (as it produces smaller instrumentation overhead and code compilation is faster) or when you need just rough information about coverage

 

Showing Clover coverage annotations in Java source editors

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 one of three toggles:

  • "Show All"
  • "Show Uncovered"
  • "Show None"

This setting applies to all Clover-enabled projects in the workspace.

 


Now you have your project instrumentation tuned to your needs. Are you looking for more tweaks? Read the 5. Eclipse configuration options chapter.

 

最終更新日 2012 年 9 月 7 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.