---
title: TestNG Integration with CI Insights
description: Report your test results from TestNG 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 TestNG tests and upload
them to **CI Insights** using a GitHub Actions 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

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

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

Run tests with:

```bash
./gradlew 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 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 TestNG Tests and Generate JUnit Report
  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
  continue-on-error: true
  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 TestNG tests.
2. JUnit-compatible XML reports are generated.
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>JUnit Listener: Ensure the JUnitReportReporter listener is properly configured in your TestNG setup.</li>

  <CommonTroubleshootingTips />
</ul>
