---
title: TestNG Integration with Mergify
description: Report your test results from TestNG tests to Mergify
---

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

## Generate a JUnit Report with TestNG

TestNG can generate JUnit-compatible XML reports. You need to configure your
build tool to enable JUnit report generation alongside the default TestNG
reports.

### Using Maven

Configure the Surefire plugin in your `pom.xml` to generate JUnit reports:

```xml
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.5.3</version>
    <configuration>
        <properties>
            <property>
                <name>usedefaultlisteners</name>
                <value>false</value>
            </property>
            <property>
                <name>listener</name>
                <value>org.testng.reporters.JUnitReportReporter</value>
            </property>
        </properties>
        <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
    </configuration>
</plugin>
```

Run tests with:

```bash
mvn test
```

### Using Gradle

Gradle's `test` task writes JUnit XML reports without any extra configuration.
Point the task at TestNG in your `build.gradle`:

```groovy
test {
    useTestNG()
}
```

Run tests with:

```bash
./gradlew test
```

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

### Using TestNG Directly

You can also run TestNG directly with JUnit listener:

```bash
java -cp "your-classpath" org.testng.TestNG -listener org.testng.reporters.JUnitReportReporter testng.xml
```

## Update Your CI Workflow

### GitHub Actions

<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 TestNG Tests and Generate JUnit Report
  id: tests
  continue-on-error: true
  run: mvn test
```

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

For Gradle projects:

```yaml
- name: Run TestNG Tests and Generate JUnit Report
  id: tests
  continue-on-error: true
  run: ./gradlew test
```

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

<GhaMergifyCiQuarantineSetup />

### Buildkite

For Maven projects:

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

For Gradle projects:

<BuildkiteCIUploadStep reportPath="build/test-results/test/*.xml" />
<BuildkiteCIUploadStepMatrix reportPath="build/test-results/test/*.xml" />

<BuildkiteCIQuarantineSetup />

### Any CI (Mergify CLI)

For Maven projects:

<MergifyCliUploadStep reportPath="target/surefire-reports/*.xml" testCommand="mvn test" />

For Gradle projects:

<MergifyCliUploadStep reportPath="build/test-results/test/*.xml" testCommand="./gradlew test" />

## Verify and Review in Test Insights

After pushing these changes:

1. Your GitHub Actions workflow will execute your TestNG tests.
2. JUnit-compatible XML reports are generated.
3. The Mergify CI action uploads the reports to Test Insights.

<ReviewInTestInsights />

## Troubleshooting Tips

<ul>
  <li>JUnit Listener: Ensure the JUnitReportReporter listener is properly configured in your TestNG setup.</li>

  <CommonTroubleshootingTips />
</ul>
