Code coverage
Code coverage in IntelliJ IDEA allows you to see the extent to which your code has been executed. It also lets you verify the extent to which your code is covered by unit tests, so that you can estimate how effective these tests are.

Code coverage is supported only for the classes and sources that belong to your current project.
The following code coverage runners are available in IntelliJ IDEA:
- IntelliJ IDEA code coverage runner (recommended)
- JaCoCo
Read in this section:
- Configure coverage
- Run with coverage
- Manage coverage suites
- Save coverage data to a file
Как узнать процент покрытия кода тестами JUnit в IntelliJ IDEA?

В правом боку «Editor» откроется таблица в которой показано покрытие кода в процентах и внизу появится пункт «Coverage».
Отслеживать
ответ дан 2 июл 2017 в 11:35
1,240 9 9 серебряных знаков 17 17 бронзовых знаков
Edit Configurations -> Add new configuration -> JUnit

Test kind: All in package и в поле package выберите корневой пакет проекта (Если вам нужно прогнать все тесты)

На закладке «Code Coverage» выберите корневой пакет проекта (опять же, если надо прогнать все тесты).

Конфигурацию настроили. Её необходимо запускать кнопкой «Run with Coverage» (см. картинку ниже). В результате вы получите процент покрытия, а в подарок увидите детализацию, какие именно строки покрыты, а какие — нет.
Configure coverage

- Press Control+Alt+S to open the IDE settings and then select Build, Execution, Deployment | Coverage .
- 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 implicitly declared default constructors : exclude the implicitly declared default constructors from coverage statistics. No-arg 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.
- Select the Activate Coverage View checkbox to open the Coverage tool window automatically.
Change colors of the coverage highlighting

- Press Control+Alt+S to open the IDE settings and then select Editor | Color Scheme | General .
- Alternatively, click in the popup that opens on clicking the coverage indication line in the gutter.
- In the list of components, expand the Line Coverage node and select a type of coverage: for example, Full , Partial or Uncovered .
- Click the Foreground field to open the Select Color dialog.
- Select a color, apply the changes, and close the dialog.
Last modified: 26 June 2023
Read the coverage report
Code coverage results are displayed in the Coverage tool window, in the Project tool window, and in the editor after you run at least one configuration with coverage.

Results of the code coverage analysis are saved to the coverage folder in the IDE system directory.
Coverage in the Project tool window
The Project tool window displays the percentage of the covered classes and lines for directories and the percentage of the covered methods and lines for classes.

Coverage in the Coverage tool window
The Code Coverage tool window appears right after you run a configuration with coverage and displays the coverage report. If you want to reopen the Coverage tool window, select Run | Show Code Coverage Data from the main menu, or press Control+Alt+F6 .
The report shows the percentage of the code that has been executed or covered by tests. You can see the coverage result for classes, methods, and lines.
Branch coverage shows the percentage of the executed branches in the source code (normally, these are the if / else and switch statements). This information is available for the JaCoCo runner and for the IntelliJ IDEA runner with the Tracing option enabled.

Code Coverage tool window options
Show all packages on the same level.
If this option is on, IntelliJ IDEA automatically opens the selected item in the editor. Otherwise, you need to double-click items to open them.
If this option is on, IntelliJ IDEA automatically locates in the tool window the files that you open in the editor.
Generate a code coverage report and save it to the specified directory. For more information, refer to Save coverage data to a file.
Filter coverage results. You can display only the classes with uncommitted changes to focus on recent updates or hide the classes that are fully covered with tests.
If you want to jump to the source code in the editor, right-click the necessary class in the Code Coverage tool window and select Jump to Source F4 .
Coverage results in the editor
In the editor, lines of code are highlighted with regard to their code coverage status in the gutter:
- Green: lines that have been executed during simulation
- Red: lines that haven’t been executed during simulation
- Yellow: lines covered with condition-tracing mode
To find out how many times a line has been run, click the color indicator in the gutter. A popup that opens shows the statistic for the line at caret. For the lines with conditions, the popup also provides statistics.

For JUnit tests, you can open the test that covers a line in a separate dialog. To do so, click the icon in the popup. To be able to use this feature, enable the Tracing mode and Track per test coverage options for the current run/debug configuration in the Code Coverage area. For more information, refer to Set coverage in run configurations.
Click to open the bytecode of the current class in a separate dialog, or to change the colors of the coverage indicators in the gutter.