| title | Configuring gotestsum |
|---|---|
| description | A guide for generating Trunk-compatible test reports for Go tests |
You can automatically detect and manage flaky tests in your Go projects by integrating with Trunk. This document explains how to configure Go to output JUnit XML reports that can be uploaded to Trunk for analysis.
The standard Go test runner, go test, is excellent for executing tests and providing immediate feedback to developers. However, it does not natively produce test reports in the JUnit XML format that Trunk Flaky Tests requires for ingestion and analysis. Therefore, an additional tool is needed to convert the output of go test into this compatible format. This intermediate step allows Trunk to accurately process your test results and identify flaky tests.
By the end of this guide, you should achieve the following before proceeding to the next steps to configure your CI provider.
- Generate a compatible test report (JUnit XML).
- Configure the report file path or glob
- Disable retries for better detection accuracy
- Test uploads locally
After correctly generating reports following the above steps, you'll be ready to move on to the next steps to configure uploads in CI.
Before integrating with Trunk, you need to generate a Trunk-compatible report. For Go, go test does not output JUnit XML by default, so you must use a tool to format it.
{% tabs %}
{% tab title="go test + go-junit-report" %}
Update your existing go test usage to generate json and use go-junit-report to convert your standard Go testing output into JUnit XML.
go install github.com/jstemmer/go-junit-report/v2@latest
Then pipe go test into the go-junit-report:
go test -json 2>&1 | go-junit-report -parser gojson -out junit_report.xml
{% endtab %}
{% tab title="gotestsum" %}
Install gotestsum into your project:
go install gotest.tools/gotestsum@latest
Call gotestsum to both execute your tests and generate the junit.xml file
gotestsum [path-to-tests-to-run] --junitfile ./junit.xml
{% endtab %} {% endtabs %}
Since go test doesn't directly output JUnit XML, you'll use a tool to convert its output. Here are two common options:
- What it is:
gotestsumis a Go test runner that wrapsgo test. It executes your tests (usinggo test -jsonfor more structured input) and can format the results into JUnit XML, alongside other human-readable formats and test run summaries. - Why choose this approach: You might prefer
gotestsumif you favor using a single command that serves as a wrapper to both execute your Go tests (by callinggo testinternally) and directly generate the JUnit XML report required for flaky test analysis. - Installation: Download from releases or install via
go install:
go install gotest.tools/gotestsum@latest- Usage:
gotestsum --junitfile ./junit-gotestsum.xml -- ./...
# The '-- ./...' passes arguments directly to 'go test'.
# Adjust './...' to target your specific packages if needed.- What it is:
go-junit-reportis a tool that converts the output of a standardgo testcommand into JUnit XML. This is achieved by runninggo testand then piping its output togo-junit-reportas a separate step. - Why choose this approach: You might prefer
go-junit-reportif you want to keep yourgo testcommand distinct and add a separate, explicit step for converting its output to JUnit XML, often suitable for a minimal setup focused purely on this conversion. - Installation:
go install github.com/jstemmer/go-junit-report/v2@latest- Usage: For reliable report generation, use
go test -jsonand pipe its output. The-parser gojsonflag tellsgo-junit-reportto expect this JSON stream:
go test -json ./... 2>&1 | go-junit-report -parser gojson -out report-go-junit.xml
# Adjust './...' to target your specific packages.
# 2>&1 ensures stderr (where build errors can appear) is also piped.The tools will write a JUnit test report to the file specified (e.g., junit-gotestsum.xml or report-go-junit.xml). You'll need this path when configuring uploads to Trunk.
Regardless of the tool chosen, you need to disable automatic retries if you previously enabled them. Retries compromise the accurate detection of flaky tests.
If you're using a package like retry, disable it to get more accurate results from Trunk.
{% tabs %} {% tab title="Linux (x64)" %}
SKU="trunk-analytics-cli-x86_64-unknown-linux.tar.gz"
curl -fL --retry 3 \
"https://github.com/trunk-io/analytics-cli/releases/latest/download/${SKU}" \
| tar -xz
chmod +x trunk-analytics-cli
./trunk-analytics-cli validate --junit-paths "./junit.xml"{% endtab %}
{% tab title="Linux (arm64)" %}
SKU="trunk-analytics-cli-aarch64-unknown-linux.tar.gz"
curl -fL --retry 3 \
"https://github.com/trunk-io/analytics-cli/releases/latest/download/${SKU}" \
| tar -xz
chmod +x trunk-analytics-cli
./trunk-analytics-cli validate --junit-paths "./junit.xml"{% endtab %}
{% tab title="macOS (arm64)" %}
SKU="trunk-analytics-cli-aarch64-apple-darwin.tar.gz"
curl -fL --retry 3 \
"https://github.com/trunk-io/analytics-cli/releases/latest/download/${SKU}" \
| tar -xz
chmod +x trunk-analytics-cli
./trunk-analytics-cli validate --junit-paths "./junit.xml"{% endtab %}
{% tab title="macOS (x64)" %}
SKU="trunk-analytics-cli-x86_64-apple-darwin.tar.gz"
curl -fL --retry 3 \
"https://github.com/trunk-io/analytics-cli/releases/latest/download/${SKU}" \
| tar -xz
chmod +x trunk-analytics-cli
./trunk-analytics-cli validate --junit-paths "./junit.xml"{% endtab %} {% endtabs %}
Before modifying your CI jobs to automatically upload test results to Trunk, try uploading a single test run manually.
You make an upload to Trunk using the following command:
./trunk-analytics-cli upload --junit-paths "./junit.xml" \
--org-url-slug <TRUNK_ORG_SLUG> \
--token <TRUNK_ORG_TOKEN>You can find your Trunk organization slug and token in the settings or by following these instructions. After your upload, you can verify that Trunk has received and processed it successfully in the Uploads tab. Warnings will be displayed if the report has issues.

Configure your CI to upload test runs to Trunk. Find the guides for your CI framework below:
| Azure DevOps Pipelines | azure-devops-pipelines.md | azure.png | |
| BitBucket Pipelines | bitbucket-pipelines.md | bitbucket.png | |
| BuildKite | buildkite.md | buildkite.png | |
| CircleCI | circleci.md | circle-ci.png | |
| Drone CI | droneci.md | drone.png | |
| GitHub Actions | github-actions.md | github.png | |
| GitLab | gitlab.md | gitlab.png | |
| Jenkins | jenkins.md | jenkins.png | |
| Semaphore | semaphoreci.md | semaphore.png | |
| TeamCity | broken-reference | teamcity.png | |
| Travis CI | travisci.md | travis.png | |
| Other CI Providers | otherci.md | other.png |