This topic explains how to collect coverage information for JUnit tests executed in IntelliJ IDEA.

Introduction

Jtest can collect coverage information for JUnit tests when a run configuration is executed in IntelliJ IDEA. To enable collecting coverage with Jtest, you can do one of the following:

  • Execute tests using the 'Jtest' run configuration shipped with Jtest.
  • Customize a run configuration created on the base of IntelliJ's JUnit or Gradle1 templates to collect coverage with the Jtest runner; then execute tests using the customized run configuration.

1 Configuring the Jtest coverage runner for Gradle run configurations is supported for IntelliJ 2019.3 and later.

Running the Jtest Run Configuration

  1. Select and right-click a scope in the Project tool window.
  2. Choose Jtest [...] from the context menu.

To customize the Jtest run configuration, open the Startup/Connection tab of your run JUnit configuration and select Jtest.

The following options are available:

  • Enable Unit Test Assistant -  If enabled, your tests will be run with Unit Test Assistant, which can help you improve the test quality. See Working with Unit Test Assistant for more information.
  • Enforce coverage with Jtest coverage runner - If enabled, coverage will be collected with the Jtest coverage runner - even if another runner is selected in the Code Coverage tab.
  • Activate Parasoft Coverage view - If enabled, the Parasoft Coverage view will automatically open when the tests are run.

Running a Customized IntelliJ Run Configuration

When you run your tests with a run configuration created on the base of  IntelliJ's template run configuration, you can configure your run configuration to collect coverage with the Jtest coverage runner.

  1. Choose Run> Edit Configurations... from the main IDE menu and choose the JUnit or Gradle configuration you want to modify.
  2. Open the Code Coverage tab.
  3. Select Jtest form the Choose coverage runner drop-down menu.
  4. Define other options available in the Code Coverage tab, such as customizing coverage scope, or collecting coverage data for folders with tests. These default IntelliJ options will be applied when the configuration is run.
  5. Click Apply.

When the test configuration is run, coverage is collected with the Jtest coverage runner and displayed in the Jtest Coverage view (see Viewing Coverage for details).

Customizing Run Configuration Templates

Customizing IntelliJ's JUnit or Gradle run configuration templates (in some IntelliJ version known as "defaults") allows you to configure collecting coverage with Jtest coverage runner for all JUnit or Gradle run configurations you create. Go to Run> Edit Configurations..., choose the JUnit or Gradle temple, open the Code Coverage tab, and select the Jtest coverage runner from the drop-down menu.

Executing and Collecting Coverage for Test Suites

By default, IntelliJ narrows down the coverage scope to the packages you selected. For this reason, if you execute a test suite, coverage is only collected for tests that are in the same package as the test suite. To ensure that coverage is collected for all tests listed in a test suite, you may need to clear the list of includes automatically generated by IntelliJ in the run configuration.

  1. Go to Run> Edit Configurations... and select your test configuration.
  2. Open the Code Coverage tab.
  3. Disable all included resources (the UI may vary depending on your IntelliJ version).
  • No labels