Page tree

Skip to end of metadata
Go to start of metadata


Jtest can collect coverage information for JUnit tests or Java applications when a run configuration is executed in Eclipse. This section describes how to enable collecting coverage for JUnit tests. For information about collecting coverage for Java applications, see Collecting Coverage for Java Applications in Eclipse.

Collecting Coverage During Unit Test Execution

You can collect coverage information for JUnit tests by running a dedicated Jtest configuration. Right-click a test or package in the Package Explorer and choose Jtest As> JUnit Test.

Alternatively, you can choose Run>Jtest As> JUnit Test from the IDE main menu or from the drop-down menu of the Launch [run_configuration_name]  toolbar button 

The coverage information will be displayed in the Coverage view, as well as color-coded markers in the editor (see Viewing Coverage).

Customizing Collecting Coverage

  1. Open the Jtest Configurations... dialog in one of the following ways:
    - Right-click a file or package in the Package Explorer and choose Jtest As> Jtest Configurations... in the Eclipse context menu
    - Choose Run> Jtest Configurations... in the IDE main menu.
    - Choose Jtest As> Jtest Configurations... from the drop-down menu of the Launch [run_configuration_name]  toolbar button 
  2. Select a run configuration and click the Jtest tab.
  3. Enable or disable the Enable coverage option. If enabled, coverage information will be collected when the test configuration is run. This option is enabled by default.

  4. Enable or disable the Enable Unit Test Assistant option. If enabled, your tests will be run with Unit Test Assistant, which can help you improve the test quality. See Creating, Analyzing and Enhancing Tests with Unit Test Assistant for more information.

  5. Click Apply.

Customizing Coverage Scope

By default, coverage is collected and reported for the project that includes the tested class and its depending projects. The projects included in the scope are displayed in the Included Projects field in the Jtest tab.

You can narrow the coverage scope to include only the items selected in your Eclipse Package Explorer or to exclude specified classes, see Reporting Coverage for Selected Items.

In addition, you can include or exclude test classes from the scope. The Collect coverage for test classes option must be enabled to activate collecting coverage for your tests. If disabled, coverage for test classes will not be collected. This option is enabled by default.

Reporting Coverage for Selected Items

To collect coverage data for only the items selected in the Package Explorer view of your IDE.

  1. Open the Jtest Configurations dialog (as described in Customizing Collecting Coverage).
  2. Select a configuration and click the Jtest tab. 
  3. Enable the Report coverage for selection only option.

  4. Click Apply.

The Included Projects field will be disabled and coverage will be reported only for the items selected in the Package Explorer.  

Excluding Classes from Instrumentation

You can specify which classes should not be included in the coverage scope. 

  1. Open the Jtest Configurations dialog (as described in Customizing Collecting Coverage).
  2. Select a configuration and click the Jtest tab. The Exclude field defines which packages should be excluded. 

  3. Click New to specify the patterns for excluding packages. You can manually enter a pattern or use the browsing interface to find packages.

  4. Click Apply.

Examples of Exclude Patterns

If you specify exclude patterns manually, use the * wildcard to exclude all the classes that are included directly in a given package.

  • examples/* - Matches all classes directly in the examples package (e.g. examples.Foo). The examples.internal.Foo class will NOT be excluded with this pattern.
  • examples/Foo* - Matches all classes in the examples package whose class file names start with "Foo" (e.g. examples.FooFile).  The examples.internal.FooFile class will NOT be excluded from the scope, as it belongs to another package.

Viewing Coverage

You can view coverage for the executed code with the Coverage view (see Viewing Coverage).

  • No labels