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:

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:

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).