Run with 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.
Go to
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.
Open the Code Coverage tab and select a code coverage runner from the Choose coverage runner list: IntelliJ IDEA or JaCoCo.
(For the IntelliJ IDEA runner) select Branch coverage to collect information for all branches of
if
andswitch
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.
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 , then click Add Class or Add Package, and select the necessary items.
To collect code coverage statistics for tests, select the Enable coverage in test folders checkbox.
Go to
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.
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.
Run a configuration with coverage
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.
Select the configuration from the list on the toolbar and click or select
from the main menu.(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.