Introduction

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. You can view the coverage scope in the Included Projects section of the Jtest tab.

Jtest allows you to narrow down the coverage scope. You can:

  • only include the items selected in your Eclipse Package Explorer.
  • exclude tests.
  • exclude selected packages.

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 to only include the items selected in your IDE. This will automatically exclude all other sources from the coverage scope.



  4. Click Apply.

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

Excluding Tests from Coverage Scope

By default, Jtest collects coverage for tests. To exclude tests from the coverage scope:

  1. Open the Jtest Configurations dialog (as described in Customizing Collecting Coverage).
  2. Select a configuration and click the Jtest tab. 
  3. Disable the Enable collecting coverage for tests option.
  4. Click Apply.

As a result, Jtest will disable collecting coverage for folders that are defined in the project properties as test folders (folders that contain test sources).

Collecting coverage for tests in different Eclipse versions

Due to the differences between Eclipse versions, the 'Enable collecting coverage for tests' option applies to either test folders or test classes:

  • In Eclipse 4.8 or later, it applies to folders that are defined in the project properties as test folders (folders that contain test sources). For this reason, to prevent collecting coverage for your test, you need to ensure that test folders are properly defined in your project.
  • In Eclipse 4.7 or earlier, it applies to test classes (JUnit 4 or 5 annotated classes). For this reason, excluding tests from coverage is not supported if you are using the Jacoco engine, which relies on test folders defined in project properties.

Excluding Selected Packages from Coverage Scope

You can specify which packages you want to exclude from the coverage scope. 

  1. Open the Jtest Configurations dialog (as described in Customizing Collecting Coverage).
  2. Select a configuration and open the Jtest tab.
  3. Click Add Package in the Excluded Packages section.

  4. Select one or more packages from the list of available packages and click OK.
  5. Click Apply. The package(s) you selected will be excluded from the coverage scope.

Viewing Coverage

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


  • No labels