> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trunk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Go

> A guide for generating Trunk-compatible test reports for Go tests

You can automatically [detect and manage flaky tests](../../detection/) 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](../ci-providers/).

**1. [Generate a compatible test report (JUnit XML)](#generating-junit-xml-reports-from-go-tests)**

**2. [Configure the report file path or glob](#report-file-path)**

**3. [Test uploads locally](#try-it-locally)**

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

> [tab] go test + go-junit-report
>
> Update your existing `go test` usage to generate json and use [**go-junit-report**](https://github.com/jstemmer/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
> ```

> [tab] 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
> ```

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

> [!NOTE]
>
> If a subtest's top-level duration is reported as 0ms, timing-based analysis in the dashboard has less to work with for that case. See [Known limitations](https://docs.trunk.io/flaky-tests/dashboard.md#known-limitations) for the recommended workaround.

## Try It Locally

```bash Linux (x64) theme={"system"}
SKU="trunk-analytics-cli-x86_64-unknown-linux.tar.gz"
VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4)
curl -fL --retry 3 \
  "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \
  | tar -xz

chmod +x trunk-analytics-cli
./trunk-analytics-cli validate --junit-paths "./junit.xml"
```

```bash Linux (arm64) theme={"system"}
SKU="trunk-analytics-cli-aarch64-unknown-linux.tar.gz"
VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4)
curl -fL --retry 3 \
  "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \
  | tar -xz

chmod +x trunk-analytics-cli
./trunk-analytics-cli validate --junit-paths "./junit.xml"
```

```bash macOS (arm64) theme={"system"}
SKU="trunk-analytics-cli-aarch64-apple-darwin.tar.gz"
VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4)
curl -fL --retry 3 \
  "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \
  | tar -xz

chmod +x trunk-analytics-cli
./trunk-analytics-cli validate --junit-paths "./junit.xml"
```

```bash macOS (x64) theme={"system"}
SKU="trunk-analytics-cli-x86_64-apple-darwin.tar.gz"
VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4)
curl -fL --retry 3 \
  "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${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:

```sh theme={"system"}
./trunk-analytics-cli upload --junit-paths "./junit.xml" \
    --org-url-slug <TRUNK_ORG_URL_SLUG> \
    --test-collection-id <TRUNK_TEST_COLLECTION_ID> \
    --token <TRUNK_ORG_TOKEN>
```

You can find your Trunk organization slug and token in the settings or by following these [instructions](https://docs.trunk.io/flaky-tests/get-started/ci-providers/otherci.md#trunk-organization-slug-and-token). The collection ID identifies the [test collection](https://docs.trunk.io/flaky-tests/test-collections.md) the results belong to, and you copy it from that collection in the Trunk app. 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.

![](https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/data-uploads-light.png?fit=max\&auto=format\&n=FEDBBs5EPDEY6kRF\&q=85\&s=6f68ed972b84c450784f8e1bd6840dc5)

## Next Steps

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

> [card] [Azure DevOps Pipelines](https://docs.trunk.io/flaky-tests/get-started/ci-providers/azure-devops-pipelines.md)

> [card] [BitBucket Pipelines](https://docs.trunk.io/flaky-tests/get-started/ci-providers/bitbucket-pipelines.md)

> [card] [BuildKite](https://docs.trunk.io/flaky-tests/get-started/ci-providers/buildkite.md)

> [card] [CircleCI](https://docs.trunk.io/flaky-tests/get-started/ci-providers/circleci.md)

> [card] [Drone CI](https://docs.trunk.io/flaky-tests/get-started/ci-providers/droneci.md)

> [card] [GitHub Actions](https://docs.trunk.io/flaky-tests/get-started/ci-providers/github-actions.md)

> [card] [GitLab](https://docs.trunk.io/flaky-tests/get-started/ci-providers/gitlab.md)

> [card] [Jenkins](https://docs.trunk.io/flaky-tests/get-started/ci-providers/jenkins.md)

> [card] [Semaphore](https://docs.trunk.io/flaky-tests/get-started/ci-providers/semaphoreci.md)

> [card] TeamCity

> [card] [Travis CI](https://docs.trunk.io/flaky-tests/get-started/ci-providers/travisci.md)

> [card] [Other CI Providers](https://docs.trunk.io/flaky-tests/get-started/ci-providers/otherci.md)
