> ## Documentation Index
> Fetch the complete documentation index at: https://trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p.mintlify.site/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/).

<Steps>
  <Step title={<a href="#generating-reports">Generate a compatible test report</a>} />

  <Step title={<a href="#report-file-path">Configure the report file path or glob</a>} />

  <Step title={<a href="#disable-retries">Disable retries for better detection accuracy</a>} />

  <Step title={<a href="#try-it-locally">Test uploads locally</a>} />
</Steps>

## 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={null}
[profile.ci.junit]
path = "junit.xml"
```

You can invoke this profile when running tests with:

```sh theme={null}
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`.

### Disable Retries

You need to disable automatic retries if you previously enabled them. Retries compromise the accurate detection of flaky tests.

Omit the `--retries` option.

## Try It Locally

### The Validate Command

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

<CodeGroup>
  ```bash Linux (x64) theme={null}
  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 "./target/nextest/ci/junit.xml"
  ```

  ```bash Linux (arm64) theme={null}
  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 "./target/nextest/ci/junit.xml"
  ```

  ```bash macOS (arm64) theme={null}
  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 "./target/nextest/ci/junit.xml"
  ```

  ```bash macOS (x64) theme={null}
  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 "./target/nextest/ci/junit.xml"
  ```
</CodeGroup>

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={null}
./trunk-analytics-cli upload --junit-paths "./target/nextest/ci/junit.xml" \
    --org-url-slug <TRUNK_ORG_SLUG> \
    --token <TRUNK_ORG_TOKEN>
```

## Next Steps

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

<Columns cols={3}>
  <Card title="Azure DevOps Pipelines" href="../ci-providers/azure-devops-pipelines" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/kkJ53_SD30K6wCtH/assets/azure.png?fit=max&auto=format&n=kkJ53_SD30K6wCtH&q=85&s=d186b34a189a5e5e73836119c2b9f108" width="1600" height="1000" data-path="assets/azure.png" />

  <Card title="BitBucket Pipelines" href="../ci-providers/bitbucket-pipelines" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/nr1u_Vl6cx4hV8Yf/assets/bitbucket.png?fit=max&auto=format&n=nr1u_Vl6cx4hV8Yf&q=85&s=4d69f68a17cdec86d0212ff117b5bf0f" width="1600" height="1000" data-path="assets/bitbucket.png" />

  <Card title="BuildKite" href="../ci-providers/buildkite" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/nr1u_Vl6cx4hV8Yf/assets/buildkite.png?fit=max&auto=format&n=nr1u_Vl6cx4hV8Yf&q=85&s=7eb9c75056a1ef3cf4c60f5d438c0060" width="1600" height="1000" data-path="assets/buildkite.png" />

  <Card title="CircleCI" href="../ci-providers/circleci" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/nr1u_Vl6cx4hV8Yf/assets/circle-ci.png?fit=max&auto=format&n=nr1u_Vl6cx4hV8Yf&q=85&s=5b7fbfb22d81a7f26c1ec3ca4dfc9d8c" width="1600" height="1000" data-path="assets/circle-ci.png" />

  <Card title="Drone CI" href="../ci-providers/droneci" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/CG6BEuLV5vq1QP0j/assets/drone.png?fit=max&auto=format&n=CG6BEuLV5vq1QP0j&q=85&s=ec72b238970e1d182da85a6d8a4cfad6" width="1600" height="1000" data-path="assets/drone.png" />

  <Card title="GitHub Actions" href="../ci-providers/github-actions" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/CG6BEuLV5vq1QP0j/assets/github.png?fit=max&auto=format&n=CG6BEuLV5vq1QP0j&q=85&s=04d01d7d34a6318e1bd2023ff4fcb415" width="1600" height="1000" data-path="assets/github.png" />

  <Card title="GitLab" href="../ci-providers/gitlab" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/CG6BEuLV5vq1QP0j/assets/gitlab.png?fit=max&auto=format&n=CG6BEuLV5vq1QP0j&q=85&s=8b57ff635f84252f067b1dc9e37b3120" width="1600" height="1000" data-path="assets/gitlab.png" />

  <Card title="Jenkins" href="../ci-providers/jenkins" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/CG6BEuLV5vq1QP0j/assets/jenkins.png?fit=max&auto=format&n=CG6BEuLV5vq1QP0j&q=85&s=46dfe15515e1862eb2f532447e5e5ecb" width="1600" height="1000" data-path="assets/jenkins.png" />

  <Card title="Semaphore" href="../ci-providers/semaphoreci" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/g--h15jA8XYvhY7h/assets/semaphore.png?fit=max&auto=format&n=g--h15jA8XYvhY7h&q=85&s=f1087e8d131213b5bed574b2e9ab6c9f" width="1600" height="1000" data-path="assets/semaphore.png" />

  <Card title="TeamCity" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/g--h15jA8XYvhY7h/assets/teamcity.png?fit=max&auto=format&n=g--h15jA8XYvhY7h&q=85&s=e77f485183ada4019f6a913f2ef9441b" width="1600" height="1000" data-path="assets/teamcity.png" />

  <Card title="Travis CI" href="../ci-providers/travisci" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/g--h15jA8XYvhY7h/assets/travis.png?fit=max&auto=format&n=g--h15jA8XYvhY7h&q=85&s=859354bbf2da08a7d4bc0de884f20c2a" width="1600" height="1000" data-path="assets/travis.png" />

  <Card title="Other CI Providers" href="../ci-providers/otherci" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-changelog-merge-queue-stacked-p/TPqhQrSRtSjefQ9U/assets/other.png?fit=max&auto=format&n=TPqhQrSRtSjefQ9U&q=85&s=c8c50a96664064040509ceed461759d4" width="1600" height="1000" data-path="assets/other.png" />
</Columns>
