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

# cargo-nextest

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

You can automatically [detect and manage flaky tests](../../detection/) in your Rust projects by integrating with Trunk. This document explains how to configure cargo-nextest 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

`cargo-nextest` has built-in reporting for JUnit XML reports, which is trunk-compatible. You can enable JUnit reporting by adding the following to your nextest config:

```toml title=".config/nextest.toml" theme={"system"}
[profile.ci.junit]
path = "junit.xml"
```

You can invoke this profile when running tests with:

```sh theme={"system"}
cargo nextest run --profile ci
```

### Report File Path

`cargo-nextest` outputs artifacts at `target/nextest` by default. When you provide a profile and a file name via the config example above, it produces a report at `target/nextest/ci/junit.xml`.

## Try It Locally

### The Validate Command

You can validate your test reports using the [Trunk Analytics CLI](https://docs.trunk.io/flaky-tests/reference/cli-reference.md). If you don't have it installed already, you can install and run the `validate` command like this:

```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 "./target/nextest/ci/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 "./target/nextest/ci/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 "./target/nextest/ci/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 "./target/nextest/ci/junit.xml"
```

This will not upload anything to Trunk. To improve detection accuracy, you should address all errors and warnings before proceeding to the next steps.

### 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 "./target/nextest/ci/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)
