> ## Documentation Index
> Fetch the complete documentation index at: https://trunk-4cab4936-mintlify-bab0b22b.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Dart Test

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

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

Before you can upload to Trunk, you need to output a Trunk-compatible report. Dart supports JUnit outputs by using the `tojunit` library. You can install the `tojunit` library using the following command:

```sh theme={null}
dart pub global activate junitreport
```

Then, you can convert test reports to a JUnit format by piping it to `tojunit`and piping the output to a file like this:

```sh theme={null}
dart test <TEST_PATH> --reporter json | tojunit > junit.xml
```

### Report File Path

The JUnit report is written to the location specified by the `tojunit >` pipe. In the example above, the test results will be written to `./junit.xml`.

### Disable Retries

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

Dart provides retries through the [retry class annotations](https://pub.dev/documentation/test/latest/test/Retry-class.html). Disable retry, use Trunk to [detect](../../detection/)[ flaky tests](../../detection/), and use Quarantining to isolate flaky tests dynamically at run time.

## Try It Locally

### The Validate Command

<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 "./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 "./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 "./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 "./junit.xml"
  ```
</CodeGroup>

### 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 "./junit.xml" \
    --org-url-slug <TRUNK_ORG_URL_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-mintlify-bab0b22b/WaLZ8p9eNFCrlKbP/assets/_shared/azure.png?fit=max&auto=format&n=WaLZ8p9eNFCrlKbP&q=85&s=833b9d30439639b440017797833086df" 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-bab0b22b/WaLZ8p9eNFCrlKbP/assets/_shared/bitbucket.png?fit=max&auto=format&n=WaLZ8p9eNFCrlKbP&q=85&s=f1bf0e588bd3db4fcf544a81dc997876" width="1600" height="1000" data-path="assets/_shared/bitbucket.png" />

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

  <Card title="CircleCI" href="../ci-providers/circleci" img="https://mintcdn.com/trunk-4cab4936-mintlify-bab0b22b/WaLZ8p9eNFCrlKbP/assets/_shared/circle-ci.png?fit=max&auto=format&n=WaLZ8p9eNFCrlKbP&q=85&s=3fdbb49df627bf6faa09f5f77244a953" 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-bab0b22b/WaLZ8p9eNFCrlKbP/assets/_shared/drone.png?fit=max&auto=format&n=WaLZ8p9eNFCrlKbP&q=85&s=f0a83aaa414c69bad79a63457b74d3b6" 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-bab0b22b/WaLZ8p9eNFCrlKbP/assets/_shared/github.png?fit=max&auto=format&n=WaLZ8p9eNFCrlKbP&q=85&s=20fefd18f727d4ab6806645e78cf6da0" width="1600" height="1000" data-path="assets/_shared/github.png" />

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

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

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

  <Card title="TeamCity" img="https://mintcdn.com/trunk-4cab4936-mintlify-bab0b22b/WaLZ8p9eNFCrlKbP/assets/_shared/teamcity.png?fit=max&auto=format&n=WaLZ8p9eNFCrlKbP&q=85&s=393781416a56f0f0b0bbd266d9d39d6f" 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-bab0b22b/WaLZ8p9eNFCrlKbP/assets/_shared/travis.png?fit=max&auto=format&n=WaLZ8p9eNFCrlKbP&q=85&s=9ca026f3d218557b70ba2f3d7ee60e74" 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-bab0b22b/WaLZ8p9eNFCrlKbP/assets/_shared/other.png?fit=max&auto=format&n=WaLZ8p9eNFCrlKbP&q=85&s=d81e6cf35c49df12678455fd9d01d218" width="1600" height="1000" data-path="assets/_shared/other.png" />
</Columns>
