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

# NUnit

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

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

Trunk detects flaky tests by analyzing test results automatically uploaded from your CI jobs. You can do this by generating Trunk-compatible XML reports from your test runs.

You can do this in dotnet with the NUnit's built-in JUnit reporter:

```sh theme={null}
dotnet test -o build  -- NUnit.TestOutputXml="junit"
```

### Report File Path

.NET will output each build to the path specified by `-o <BUILD_PATH>` and test results under a sub-folder of `<BUILD PATH>/test-reports`, specified by the `-- NUnit.TestOutputXml="<XML PATH>"` option.

In the example command from the [Generating Reports step](./nunit#generating-reports), the XMLs will be located under `./build/test-reports/junit/*.xml`. This is also the glob you'll use to locate the results when uploading test results.

### Disable Retries

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

Omit `[Retry(n)]` from tests to disable retries.

## 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 "./build/test-reports/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 "./build/test-reports/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 "./build/test-reports/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 "./build/test-reports/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 "./build/test-reports/junit/*.xml" \
    --org-url-slug <TRUNK_ORG_URL_SLUG> \
    --token <TRUNK_ORG_TOKEN>
```

You can find your Trunk organization slug and token in the settings or by following these [instructions](/flaky-tests/get-started/ci-providers/otherci#id-1.-store-a-trunk_token-secret-in-your-ci-system). After your upload, you can verify that Trunk has received and processed it successfully in the **Uploads** tab. Warnings will be displayed if the report has issues.

<Frame>
  <img className="block dark:hidden" src="https://mintcdn.com/trunk-4cab4936-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/data-uploads-light.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=f66c09a37fe8b282ba16a1961f2d1283" alt="" width="2560" height="1800" data-path="assets/_shared/data-uploads-light.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/trunk-4cab4936-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/data-uploads-dark.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=0010e37bc7efbfbae8a795e5eaac84c6" alt="" width="2560" height="1800" data-path="assets/_shared/data-uploads-dark.png" />
</Frame>

## 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-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/azure.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=b5bfef96e13c23923501905870f35549" 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-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/bitbucket.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=7a7e0f03f8cf4933708f68946ec5a3b4" width="1600" height="1000" data-path="assets/_shared/bitbucket.png" />

  <Card title="BuildKite" href="../ci-providers/buildkite" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/buildkite.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=69ebeb3998ac3f60e009c053ecb2095c" width="1600" height="1000" data-path="assets/_shared/buildkite.png" />

  <Card title="CircleCI" href="../ci-providers/circleci" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/circle-ci.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=5a0395ffe0eb556b4413b3f269043840" 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-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/drone.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=c3c33712a603c5076657aff6b7058ab2" 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-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/github.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=5ce0a9b54d9856505ff216a255b8530c" width="1600" height="1000" data-path="assets/_shared/github.png" />

  <Card title="GitLab" href="../ci-providers/gitlab" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/gitlab.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=3526b20092f72c3653a6a03afccd2708" width="1600" height="1000" data-path="assets/_shared/gitlab.png" />

  <Card title="Jenkins" href="../ci-providers/jenkins" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/jenkins.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=677b75a92f610f9aabee06bf260a7c20" width="1600" height="1000" data-path="assets/_shared/jenkins.png" />

  <Card title="Semaphore" href="../ci-providers/semaphoreci" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/semaphore.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=760e76ce5520e10f50f10d70f1517428" width="1600" height="1000" data-path="assets/_shared/semaphore.png" />

  <Card title="TeamCity" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/teamcity.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=cb68ab1b2f5acd6b1a799b45e0145d9b" width="1600" height="1000" data-path="assets/_shared/teamcity.png" />

  <Card title="Travis CI" href="../ci-providers/travisci" img="https://mintcdn.com/trunk-4cab4936-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/travis.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=41b88fe3e12cd7661b43ff89d744f733" 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-sam-gutentag-parallel-cutover-docs/C2F0WpMpXMQH4lv9/assets/_shared/other.png?fit=max&auto=format&n=C2F0WpMpXMQH4lv9&q=85&s=abc943873bc19c0d94966375880ed3aa" width="1600" height="1000" data-path="assets/_shared/other.png" />
</Columns>
