IntelliJ IDEA 2017.3 Help

Code Coverage

In this section:


Measuring code coverage is available for testing, applications, and application server run/debug configurations.

The code coverage measuring can be performed using the following runners:

  • IntelliJ IDEA code coverage runner (recommended).
  • EMMA open-source toolkit. Note that EMMA is not supported by the author any more, and works with Java 7 only when frame validation turned off (pass -noverify to the process).
  • JaCoCo.

IntelliJ IDEA code coverage runner enables multi-mode analysis:

  • Sampling mode enables collecting line coverage with negligible slow-down.
  • Tracing mode enables accurate collection of the branch coverage, with the ability to track tests, view coverage statistic, and get additional information on each covered line.

For the other runners, only sampling mode is available.

Code coverage results are reflected in the dedicated Coverage tool window, in the Project view of the Project Tool Window, and in the editor. The tool windows show the following information:

  • For a directory: the percentage of the covered classes and lines.
  • For a class: the percentage of the covered methods and lines.

When a file is opened in the editor, each line is highlighted with regard to its code coverage status:

  • Lines executed during simulation are marked green.
  • Lines not executed during simulation are marked red.
  • Covered lines with conditions are marked yellow in the tracing mode.

The coverage measurement results comprise a coverage suite. You can have the results of a new simulation merged with any existing suite. In this case, a line will be considered covered if it is covered by at least one of the simulations.

A coverage suite is generated every time a test or application with code coverage measurement is executed. It is possible to have an unlimited amount of coverage suites.


Make sure the Code Coverage plugin is enabled. The plugin is activated by default. If the plugin is disabled, enable it on the Plugins settings page as described in Enabling and Disabling Plugins. If the plugin is disabled, the code coverage tabs will not be visible in the run/debug configuration dialogs.

Running with code coverage

To use code coverage in project, follow these general steps

  1. Specify how you want to process the coverage results.
  2. Create tests for the target code, if you are going to measure code coverage for testing.
  3. Configure code coverage measurement in the desired run/debug configuration.
  4. Run with coverage, using the dedicated command on the main menu Run | Run with Coverage, or runWithCoverage.
  5. Once the run with coverage has been executed, you can
Last modified: 6 March 2018

See Also