Code coverage
Manage suites: Run | Manage Coverage Reports CtrlAltF6
Coverage settings: Settings CtrlAlt0S | Build, Execution, Deployment | Coverage
Code coverage in GoLand lets you analyze which lines of code were executed during a particular run. It helps determine the share of code covered by tests and identify areas that lack sufficient test coverage.
The entry points for running coverage analysis are the same as you would normally use to run an application:
For main method definitions, click
Run in the editor gutter, then select Run with Coverage
For run configurations, click
More Actions in the Run widget, then select Run with Coverage
Coverage analysis executes the corresponding run configuration with the coverage agent attached. This agent instruments the bytecode to keep track of the execution line-by-line. After the execution completes, the results of the analysis appear in the IDE.
The collection of coverage data for a specific run is called a coverage suite.
GoLand can display the results for one or more coverage suites at once. If multiple suites are selected, the IDE displays merged results from these suites. This means that a line is considered covered if it was executed in at least one of the selected suites.
The corresponding suite files are located in the GoLand's system directory:
%LOCALAPPDATA%
~
~
In the main menu, go to Run | Manage Coverage Reports CtrlAltF6.
In the Choose Coverage Suite to Display menu:
Use the checkboxes to select active suites. Active suites define the coverage data that is currently displayed in the IDE.
Use
Add to import external suite file, for example, generated in the CI server or sent to you by someone else.
Use
Remove to remove a suite from the list but keep the file in the storage.
Use
Delete to remove a suite from the list and delete the file from the storage.
GoLand shows coverage results in:
Coverage tool window
Project tool window
Editor
note
Code coverage is only supported for the code that belongs to your current project.
Code coverage results are displayed in the Coverage tool window, in the Project tool window, and in the editor after you launch at least one run configuration with coverage.
The Project tool window displays:
the percentage of the covered classes and lines for directories
the percentage of the covered methods and lines for classes
![Code coverage results in the Project tool window Code coverage results in the Project tool window](https://resources.jetbrains.com/help/img/idea/2024.3/go-coverage-in-project-tw.png)
![Coverage results in the Coverage tool window Coverage results in the Coverage tool window](https://resources.jetbrains.com/help/img/idea/2024.3/go-coverage-tw.png)
The Coverage tool window has the following options:
Item | Description |
---|---|
If this option is on, GoLand automatically opens the selected item in the editor. Otherwise, you need to double-click items to open them. | |
If this option is on, GoLand automatically locates in the tool window the files that you open in the editor. | |
Import a coverage suite from disk. |
In the editor gutter, lines are highlighted according to their coverage status:
Green – lines that have been executed
Red – lines that have not been executed
Yellow – lines that were executed partially, like when only one branch of an
if-else
statement is visited
To view statistics for a line of code, click the corresponding color indicator in the gutter.
Do one of the following:
Close the tab with coverage statistics in the Coverage tool window (View | Tool Windows | Coverage).
Click coverage highlighting in the gutter and select Hide coverage.
Press CtrlAlt0S to open 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.
![Configure code coverage colors Configure code coverage colors](https://resources.jetbrains.com/help/img/idea/2024.3/go_coverageColors.png)
Thanks for your feedback!