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

# GoogleTest

> A guide for generating Trunk-compatible test reports for GoogleTest

You can automatically [detect and manage flaky tests](../../detection/) in your GoogleTest projects by integrating with Trunk. This document explains how to configure GoogleTest to output JUnit XML reports that can be uploaded to Trunk for analysis.

## 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](#generating-reports)**

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

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

## Generating Reports

Before you can integrate with Trunk, you need to generate a Trunk-compatible report. For GoogleTest, the built in XML reporter will work. You can use the [`--gtest_output=xml`](https://google.github.io/googletest/advanced.html#generating-an-xml-report) argument when you run your built test project:

```shell theme={"system"}
./build/run_test --gtest_output=xml
```

### Report File Path

By default, the JUnit report will be written to a `test_detail.xml` file.

You can specify a custom directory and filename with:

```bash theme={"system"}
--gtest_output=xml:<path/to/file.xml>
```

For example, the following argument writes a JUnit report to `./junit.xml`:

```bash theme={"system"}
--gtest_output=xml:junit.xml
```

## Try It Locally

### The Validate Command

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

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