# Go test coverage

However, SonarQube Server does not generate the coverage report itself. Instead, you must set up a third-party tool to produce the report as part of your build process.

You then need to configure your analysis to tell the SonarScanner where the report is located so that it can pick it up and send it to SonarQube Server, where it will be displayed on your project dashboard along with the other analysis metrics.

For Go projects, SonarQube Server supports the default Go test tooling.

## Adjust your setup <a href="#adjust-your-setup" id="adjust-your-setup"></a>

To enable coverage for Go, you need to:

* adjust your build process so that the coverage tool generates the report(s) just after your unit as part of the clean build required to run analysis
* make sure that the coverage tool writes its report file to a defined path in the build environment
* configure the scanning step of your build so that the scanner picks up the report file from that defined path

## Adding coverage to your build process <a href="#adding-coverage-to-your-build-process" id="adding-coverage-to-your-build-process"></a>

The first step is to generate the coverage reports.

The simplest way to generate a report is to run your test with the `-coverprofile=<location>` flag.

This will tell the Go tooling to generate a coverage report file at a specific location. For example, `go test -coverprofile=coverage.out` should generate a `coverage.out` report in the working directory.

## Adding the coverage analysis parameter <a href="#adding-the-coverage-analysis-parameter" id="adding-the-coverage-analysis-parameter"></a>

The next step is to add `sonar.go.coverage.reportPaths` to your analysis parameters. This parameter must be set to the path of the report file produced by your coverage tool. The parameter supports the mention of multiple coverage file reports separated by a comma.

In this example, that path is set to the default. It is set in the `sonar-project.properties` file, located in the project root:

```css-79elbk
sonar.projectKey=<sonar-project-key>
...
sonar.go.coverage.reportPaths=coverage.xml
```

### Coverage parameters can be set in multiple places <a href="#coverage-parameters-can-be-set-in-multiple-places" id="coverage-parameters-can-be-set-in-multiple-places"></a>

As with other analysis parameters, `sonar.go.coverage.reportPaths` can be set in multiple places:

* In the `sonar-project.properties` file, as mentioned above.
* On the command line of the scanner invocation using the `-D` or `--define` switch, for example,\
  `sonar-scanner -Dsonar.go.coverage.reportPaths=coverage.xml`
* In the SonarQube Server interface, in the **Path to coverage report(s)** section under:
  * *Your Project* > **Project Settings** > **General Settings** > **Languages** > **Go** for project-level settings
  * *Your Project >* **Administration** > **Configuration** > **General Settings** > **Languages** > **Go** for global settings (applying to all projects).

## Related pages <a href="#related-pages" id="related-pages"></a>

[Test coverage parameters](/sonarqube-server/2025.2/analyzing-source-code/test-coverage/test-coverage-parameters.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonarsource.com/sonarqube-server/2025.2/analyzing-source-code/test-coverage/go-test-coverage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
