> ## Documentation Index
> Fetch the complete documentation index at: https://trunk-4cab4936-mintlify-72807e6c.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="#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={"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](../../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={"system"}
  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={"system"}
  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={"system"}
  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={"system"}
  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={"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:

<Columns cols={3}>
  <Card title="Azure DevOps Pipelines" href="../ci-providers/azure-devops-pipelines" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/azure.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=f954c2c34387969701cb99e6f5d7a36b" width="1600" height="1000" data-path="assets/_shared/azure.png" />

  <Card title="BitBucket Pipelines" href="../ci-providers/bitbucket-pipelines" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/bitbucket.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=aea6e86f2e643d0ad6d8c4ab27916299" width="1600" height="1000" data-path="assets/_shared/bitbucket.png" />

  <Card title="BuildKite" href="../ci-providers/buildkite" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/buildkite.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=1fd78749515b0394b72c787642996835" width="1600" height="1000" data-path="assets/_shared/buildkite.png" />

  <Card title="CircleCI" href="../ci-providers/circleci" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/circle-ci.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=895ed8ea86ba6063449d7e8c9a1f777f" width="1600" height="1000" data-path="assets/_shared/circle-ci.png" />

  <Card title="Drone CI" href="../ci-providers/droneci" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/drone.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=630acdab7f11ddc020c0afc5351899bf" width="1600" height="1000" data-path="assets/_shared/drone.png" />

  <Card title="GitHub Actions" href="../ci-providers/github-actions" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/github.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=73e479241070dfec000ffca80acd24c7" width="1600" height="1000" data-path="assets/_shared/github.png" />

  <Card title="GitLab" href="../ci-providers/gitlab" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/gitlab.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=7b6ea4a32b207b935786524649235e79" width="1600" height="1000" data-path="assets/_shared/gitlab.png" />

  <Card title="Jenkins" href="../ci-providers/jenkins" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/jenkins.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=0baa7cb262e09867aaed0aed730eaa85" width="1600" height="1000" data-path="assets/_shared/jenkins.png" />

  <Card title="Semaphore" href="../ci-providers/semaphoreci" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/semaphore.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=e4054799d63ffa3d9965c1aa83bf9467" width="1600" height="1000" data-path="assets/_shared/semaphore.png" />

  <Card title="TeamCity" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/teamcity.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=093a7c54cf6fff64ea4ed79e7c3cd774" width="1600" height="1000" data-path="assets/_shared/teamcity.png" />

  <Card title="Travis CI" href="../ci-providers/travisci" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/travis.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=515d0b3ec093a12187ecc8b5e9f843fd" width="1600" height="1000" data-path="assets/_shared/travis.png" />

  <Card title="Other CI Providers" href="../ci-providers/otherci" img="https://mintcdn.com/trunk-4cab4936-mintlify-72807e6c/mjwZCcQhQIR2EzMR/assets/_shared/other.png?fit=max&auto=format&n=mjwZCcQhQIR2EzMR&q=85&s=eb9d656fc8561678501bc7fc716b450b" width="1600" height="1000" data-path="assets/_shared/other.png" />
</Columns>
