IntelliJ IDEA 2023.3 Help

Run with coverage

Hide coverage results

  • To hide coverage results, you can do the following:

    • Close a tab with coverage statistics in the Coverage tool window.

    • Click a coverage highlighting in a gutter and select Hide coverage.

Set coverage in run configurations

In IntelliJ IDEA, you can create multiple run/debug configurations and specify coverage options for each of them depending on your needs.

  1. Go to Run | Edit Configurations and click the necessary configuration on the left panel.

    If you haven't created the required configuration yet, refer to the Create a run/debug configuration from a template procedure that will guide you through the process.

    Code Coverage tab in the Run/debug Configuration dialog
  2. Open the Code Coverage tab and select a code coverage runner from the Choose coverage runner list: IntelliJ IDEA or JaCoCo.

  3. (For the IntelliJ IDEA runner) select Branch coverage to collect information for all branches of if and switch statements.

    Additionally, enable the Track per test coverage option that allows tracking individual code coverage produced by each test case. Enable this option if you want to know exactly what lines of code have been covered by specific tests. This will let 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.

    Click the Add button, then click the Class icon 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.

  1. Go to Run | Edit Configurations and click the necessary configuration on the left panel.

    If you haven't created the required configuration yet, refer to the Create a run/debug configuration from a template procedure that will guide you through the process.

    Code Coverage in the Run/debug Configuration dialog
  2. Click Modify options, select Coverage settings, and select the options that you want to configure:

    • Specify classes and packages: select this option to configure classes and packages for which you want to see the coverage information.

    • Exclude classes and packages: select this option to configure classes and packages that you want to exclude from coverage.

    • Specify alternative coverage runner: select this option to set a coverage runner: the IntelliJ IDEA runner or JaCoCo.

    • Use tracing: (only for the IntelliJ IDEA runner) tracing 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.

    • Collect coverage in test folders: collect code coverage statistics for tests.

    Code Coverage in the Run/debug Configuration dialog

Run a configuration with coverage

  1. Make sure that you have created the necessary run/debug configuration.

    You can also use a temporary run configuration that you can later modify, save, and rerun.

  2. Select the configuration from the list on the toolbar and click the Run with Coverage button or select Run | Run ... with Coverage from the main menu.

    Running a test with coverage
  3. (If the Show options before applying coverage to the editor option is enabled) The IDE prompts you to select whether you want to replace the active coverage suites, add the collected data to the active suites, or skip applying coverage data.

    Select whether you want to append the results of multiple runs and click OK.

Last modified: 19 March 2024