---
title: JUnit Integration with CI Insights
description: Report your test results from JUnit tests to CI Insights
---

import CommonTroubleshootingTips from "./_common-troubleshooting-tips.mdx"
import GhaMergifyCiQuarantineSetup from "./_gha_mergify_ci_quarantine_setup.mdx"
import MergifyCIUploadStep from "../../../../components/MergifyCIUploadStep.astro"
import MergifyCIUploadStepMatrix from "../../../../components/MergifyCIUploadStepMatrix.astro"
import CIInsightsSetupNote from "../../../../components/CIInsightsSetupNote.astro"

This guide shows how to generate JUnit reports from your JUnit tests and upload
them to **CI Insights** using a GitHub Actions workflow.

## Generate a JUnit Report with JUnit

JUnit naturally generates XML reports that are compatible with the JUnit format
expected by CI Insights. You can configure your build tool to output these
reports.

### Using Maven

Configure the Surefire plugin in your `pom.xml`:

```xml
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.5.3</version>
    <configuration>
        <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
    </configuration>
</plugin>
```

Run tests with:

```bash
mvn test
```

The JUnit XML reports will be generated in `target/surefire-reports/`.

### Using Gradle

Configure the test task in your `build.gradle`:

```groovy
test {
    useJUnitPlatform()
    reports {
        junitXml.enabled = true
        junitXml.destination = file("$buildDir/test-results/test")
    }
}
```

Run tests with:

```bash
./gradlew test
```

The JUnit XML reports will be generated in `build/test-results/test/`.

## Update Your GitHub Actions Workflow

<CIInsightsSetupNote />

After generating the JUnit report, add a step to upload the results to CI
Insights using the `mergifyio/gha-mergify-ci` action.

For example, in your workflow file:

```yaml
- name: Run JUnit Tests and Generate Report
  continue-on-error: true
  run: mvn test
```

Then, upload the report:

<MergifyCIUploadStep reportPath="target/surefire-reports/*.xml" />

For Gradle projects:

```yaml
- name: Run JUnit Tests and Generate Report
  run: ./gradlew test
```

<MergifyCIUploadStep reportPath="build/test-results/test/*.xml" />
<MergifyCIUploadStepMatrix reportPath="build/test-results/test/*.xml" />

<GhaMergifyCiQuarantineSetup />

## Verify and Review in CI Insights

After pushing these changes:

1. Your GitHub Actions workflow will execute your JUnit tests.
2. JUnit XML reports are generated by Maven/Gradle.
3. The Mergify CI action uploads the reports to CI Insights.

You can then review your test results, including any failures or flaky tests,
directly in the [CI Insights
dashboard](https://dashboard.mergify.com/ci-insights/jobs).

## Troubleshooting Tips

<ul>
  <li>
    Build Tool Configuration: Ensure Maven Surefire or Gradle test reporting is properly configured to generate XML
    reports.
  </li>

  <CommonTroubleshootingTips />
</ul>
