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
-noverifyto the process).
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.
- 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.
Make sure the Code Coverage plugin is enabled. The plugin is activated by default. If the plugin is disabled, enable it on the Plugins 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
- Specify how you want to process the coverage results.
- Create tests for the target code, if you are going to measure code coverage for testing.
- Configure code coverage measurement in the desired run/debug configuration.
- Run with coverage, using the dedicated command on the main menu , or .
- Once the run with coverage has been executed, you can