Skip to content

How to Integrate TestNG with TestBeats ​

This guide shows you how to send your TestNG test results to Slack, Microsoft Teams, or Google Chat using TestBeats.

What You'll Achieve ​

After following this guide, your TestNG tests will automatically send results to your team communication channels, complete with AI-powered failure analysis and detailed reporting.

Prerequisites ​

Before starting, ensure you have:

  • A Java project with TestNG tests
  • Maven or Gradle build system
  • TestBeats installed (npx testbeats@latest --version)
  • A webhook URL for your communication platform (Slack, Teams, or Chat)
  • (Optional) TestBeats API key from app.testbeats.com

Step 1: Configure TestNG to Generate XML Reports ​

TestNG needs to output test results in XML format for TestBeats to process.

Option A: Maven Configuration ​

Update your pom.xml to configure the Surefire plugin:

xml
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M9</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                </suiteXmlFiles>
                <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

Option B: Gradle Configuration ​

Update your build.gradle:

gradle
test {
    useTestNG() {
        suites 'src/test/resources/testng.xml'
        outputDir = file("$buildDir/test-results/test")
    }

    reports {
        junitXml.enabled = true
        html.enabled = true
    }
}

Option C: TestNG XML Suite Configuration ​

Create a testng.xml file in src/test/resources/:

xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="TestSuite" verbose="1">
    <test name="TestGroup">
        <classes>
            <class name="com.example.tests.LoginTest"/>
            <class name="com.example.tests.UserTest"/>
        </classes>
    </test>
</suite>

Step 2: Run Your Tests ​

Execute your TestNG tests using your build system:

Using Maven ​

bash
# Run all tests
mvn clean test

# Run specific test suite
mvn clean test -DsuiteXmlFile=src/test/resources/testng.xml

# Run with specific groups
mvn clean test -Dgroups=smoke,regression

Using Gradle ​

bash
# Run all tests
./gradlew test

# Run specific test class
./gradlew test --tests com.example.tests.LoginTest

Step 3: Choose Your Integration Method ​

You have two options to send results to TestBeats:

Option A: Command Line (Quick Setup) ​

For quick testing or simple setups:

bash
npx testbeats@latest publish \
  --api-key '<your-api-key>' \
  --slack '<your-webhook-url>' \
  --testng 'target/surefire-reports/testng-results.xml'

For more control and CI/CD integration, create a testbeats.config.json:

json
{
  "api_key": "<your-api-key>",
  "targets": [
    {
      "name": "slack",
      "inputs": {
        "url": "<your-webhook-url>"
      }
    }
  ],
  "results": [
    {
      "type": "testng",
      "files": ["target/surefire-reports/testng-results.xml"]
    }
  ]
}

Then run:

bash
npx testbeats@latest publish -c testbeats.config.json

Next Steps ​


Need help with a different framework? Check Framework Integrations →

Released under the MIT License.