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

# Kotest

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

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

Steps for generating JUnit XML reports for Kotest depend on the build system you use for your project:

<Tabs>
  <Tab title="Gradle">
    Tests run with Gradle will generate Trunk-compatible JUnit XML reports by default. You can further [configure reporting behavior](https://docs.gradle.org/8.10.2/userguide/java_testing.html#test_reporting) in your `build.gradle.kts` or `build.gradle`.
  </Tab>

  <Tab title="Maven">
    Kotest projects using Maven require the following to be added to a project's `pom.xml` so JUnit XML reports can be generated:

    * the `maven-surefire-plugin` must be added to the `plugins` section of `pom.xml`

    ```xml title="pom.xml" theme={null}
    <project>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.2.2</version>
                </plugin>
                
                <!-- other plugins -->
            </plugins>
        </build>
    </project>
    ```

    * the `kotest-extensions-junitxml` must be added to the `dependencies` section of `pom.xml`

    ```xml title="pom.xml" theme={null}
    <dependencies>
        <dependency>
            <groupId>io.kotest</groupId>
            <artifactId>kotest-extensions-junitxml-jvm</artifactId>
            <version>5.9.0</version>
            <scope>test</scope>
        </dependency>
        
        <!-- other dependencies -->
    </dependencies>
    ```
  </Tab>
</Tabs>

### Report File Path

You can configure the path for generated JUnit XML files:

<Tabs>
  <Tab title="Gradle">
    By default, Kotlin projects will produce a directory with JUnit XML reports under `./app/build/test-results/test`. You can locate these files with the glob `"./app/build/test-results/test/*.xml"`.

    If you wish to override the default test result path, you can do so in the `build.gradle.kts` or `build.gradle` files:

    ```kotlin title="build.gradle.kts (Kotlin) or build.gradle (Groovy)" theme={null}
    java.testResultsDir = layout.buildDirectory.dir("junit-reports")
    ```
  </Tab>

  <Tab title="Maven">
    You can change the report file path by configuring the `reportsDirectory` in your `maven-surefire-plugin` in your `pom.xml` file:

    ```xml title="pom.xml" theme={null}
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.2.2</version>
        <configuration>
            <reportsDirectory>${project.build.directory}/junit/</reportsDirectory>
        </configuration>
    </plugin>
    ```

    The example above will output JUnit XML reports that can be located with the `/target/junit/*.xml` glob.
  </Tab>
</Tabs>

### Disable Retries

You need to disable automatic retries if you previously enabled them. Retries compromise the accurate detection of flaky tests. You should disable retries for accurate detection and use the [Quarantining](../../quarantining/) feature to stop flaky tests from failing your CI jobs.

<Tabs>
  <Tab title="Gradle">
    If you've enabled retries using a plugin like the [test-retry-gradle-plugin](https://github.com/gradle/test-retry-gradle-plugin), disable it when running tests for Trunk Flaky Tests.
  </Tab>

  <Tab title="Maven">
    Maven uses the `maven-surefire-plugin` to run tests, which allows you to control the test retry behavior. You can disable retries by specifying 0 retries:

    ```
    mvn -Dsurefire.rerunFailingTestsCount=0 test
    ```
  </Tab>
</Tabs>

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

<Note>
  The `validate` and `upload` examples below use the **Gradle default** output path. Point `--junit-paths` at the glob that matches your build:

  * **Gradle** (default): `./app/build/test-results/test/*.xml`
  * **Gradle** with the `testResultsDir` override shown above: `./app/build/junit-reports/test/*.xml`
  * **Maven**: `./target/junit/*.xml`
</Note>

<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 "./app/build/test-results/test/*.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 "./app/build/test-results/test/*.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 "./app/build/test-results/test/*.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 "./app/build/test-results/test/*.xml"
  ```
</CodeGroup>

Make sure to specify the path to your JUnit XML test reports.

**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 "./app/build/test-results/test/*.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/FEDBBs5EPDEY6kRF/assets/_shared/data-uploads-light.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=6f68ed972b84c450784f8e1bd6840dc5" alt="" width="2560" height="1800" data-path="assets/_shared/data-uploads-light.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/data-uploads-dark.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=e5c9def4c127b684368246f169484d8a" 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="Atlassian Bamboo" href="/flaky-tests/get-started/ci-providers/atlassian-bamboo" img="https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/atlassian-bamboo.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=509de3813771912addc536f1a9da39f9" width="1600" height="1000" data-path="assets/_shared/atlassian-bamboo.png" />

  <Card title="Azure DevOps Pipelines" href="/flaky-tests/get-started/ci-providers/azure-devops-pipelines" img="https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/azure.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=ca9fc956b630fa258a9303701fd0c486" width="1600" height="1000" data-path="assets/_shared/azure.png" />

  <Card title="BitBucket Pipelines" href="/flaky-tests/get-started/ci-providers/bitbucket-pipelines" img="https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/bitbucket.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=e1ffac7bbb707e669e39b99ed1b4c06f" width="1600" height="1000" data-path="assets/_shared/bitbucket.png" />

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

  <Card title="CircleCI" href="/flaky-tests/get-started/ci-providers/circleci" img="https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/circle-ci.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=7b8ddd92e0e224f932515a46b442deb2" width="1600" height="1000" data-path="assets/_shared/circle-ci.png" />

  <Card title="Drone CI" href="/flaky-tests/get-started/ci-providers/droneci" img="https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/drone.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=cd52584e45cf1cca29fbdd6d937cbc3d" width="1600" height="1000" data-path="assets/_shared/drone.png" />

  <Card title="GitHub Actions" href="/flaky-tests/get-started/ci-providers/github-actions" img="https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/github.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=9f188c818b4496ccd94d2531f0519b2b" width="1600" height="1000" data-path="assets/_shared/github.png" />

  <Card title="GitLab" href="/flaky-tests/get-started/ci-providers/gitlab" img="https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/gitlab.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=0c24d1bc8d892672d10c05e418c43670" width="1600" height="1000" data-path="assets/_shared/gitlab.png" />

  <Card title="Jenkins" href="/flaky-tests/get-started/ci-providers/jenkins" img="https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/jenkins.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=1050e68eefdc912c6b3b940459f834ce" width="1600" height="1000" data-path="assets/_shared/jenkins.png" />

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

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

  <Card title="Travis CI" href="/flaky-tests/get-started/ci-providers/travisci" img="https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/travis.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=d932aa877961f570d15e80f61933ee56" width="1600" height="1000" data-path="assets/_shared/travis.png" />

  <Card title="Other CI Providers" href="/flaky-tests/get-started/ci-providers/otherci" img="https://mintcdn.com/trunk-4cab4936/FEDBBs5EPDEY6kRF/assets/_shared/other.png?fit=max&auto=format&n=FEDBBs5EPDEY6kRF&q=85&s=2231888b2a96f0a4fb0d2759c25c7b64" width="1600" height="1000" data-path="assets/_shared/other.png" />
</Columns>
