IntelliJ IDEA 2020.2 Help

Configure coverage measurement

Configure code coverage behavior

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Build, Execution, Deployment | Coverage.

  2. Define how the collected coverage data will be processed:

    • Show options before applying coverage to the editor: show the Code Coverage dialog every time you run a new run configuration with code coverage.

    • Do not apply collected coverage: discard the new code coverage results.

    • Replace active suites with the new one: discard the active suites and use the new one every time you launch a new run configuration with code coverage.

    • Add to the active suites: add new code coverage suites to the active suites every time you launch a new run configuration with code coverage.

    • Ignore implicit constructors: exclude implicitly declared default constructors from coverage statistics. Default constructors that are declared explicitly will remain included.

    • Ignore empty private constructors of utility classes: exclude from coverage statistics empty private constructors in classes where all other methods are static.

  3. Select the Activate Coverage View checkbox to open the Coverage tool window automatically.

Code Coverage settings page

Configure code coverage options

  1. From the main menu, select Run | Edit Configurations, add the necessary run/debug configuration, and switch to the Code Coverage tab.

  2. On the Code Coverage tab, select a code coverage from the Choose coverage runner list runner: EMMA, JaCoCo, or IntelliJ IDEA.

  3. (For the IntelliJ IDEA runner) select the mode that you want to use: Sampling or Tracing.

    • Sampling mode enables collecting line coverage with negligible slow-down.

    • Tracing mode enables the accurate collection of the branch coverage, with the ability to track tests, view coverage statistics, and get additional information on each covered line.

    • Track per test coverage option allows tracking individual code coverage produced by each test case. Enable this option if you want to know exactly what code has been covered by specific tests. You will also be able to see which tests are the most relevant for each piece of the code.

  4. The Packages and classes to include in coverage data and Packages and classes to exclude from coverage data areas allow you to narrow down the code coverage scope.

    For example, you can include or exclude specific classes and packages from coverage measurement.

    Click the Add Class button (Add Class) or the Add Package button (Add Package) and select the necessary items.

  5. To collect code coverage statistics for tests, select the Enable Coverage in Test Folders checkbox.

    Code Coverage tab in the Run/debug Configuration dialog

Change colors of the coverage highlighting

  1. In the Settings/Preferences dialog Ctrl+Alt+S, navigate to Editor | Color Scheme | General.

  2. In the list of components, expand the Line Coverage node and select a type of coverage: for example, Full, Partial or Uncovered.

  3. Click the Foreground field to open the Select Color dialog.

  4. Select a color and click Apply.

Configure code coverage colors
Last modified: 11 November 2020