Skip to main content
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.

Why an Extra Step for go test?

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.

Setup steps

Work through the steps below in order. Once you’ve finished the last one, you’ll be ready to move on to configure uploads in CI.

Generating JUnit XML Reports from Go Tests

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.
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

Report File Path

The tools will write a JUnit test report to the file specified (e.g., junit.xml or junit_report.xml). You’ll need this path when configuring uploads to Trunk.

Disable Retries

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.

Try It Locally

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"

Test Upload

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_URL_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.

Next Steps

Configure your CI to upload test runs to Trunk. Find the guides for your CI framework below:
azure

Azure DevOps Pipelines

bitbucket

BitBucket Pipelines

buildkite

BuildKite

circle-ci

CircleCI

drone

Drone CI

github

GitHub Actions

gitlab

GitLab

jenkins

Jenkins

semaphore

Semaphore

teamcity

TeamCity

travis

Travis CI

other

Other CI Providers