TestNG Integration
Run your TestNG tests as usual and have results automatically reported to ProvaLab.io. The SDK provides a comprehensive listener with full lifecycle management, log capture, and QA Infrastructure integration.
Install
Maven
<dependency>
<groupId>com.tms</groupId>
<artifactId>tms-java-sdk</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
Gradle
testImplementation 'com.tms:tms-java-sdk:2.0.0'
Requirements: Java 17+, TestNG 7.8+
Configure
1. Set environment variables
export TMS_API_KEY=your-api-key
export TMS_API_URL=https://tms.yourcompany.com
export TMS_ORGANIZATION_ID=1
export TMS_PROJECT_ID=12
2. Register the ProvaLab.io listener
Option A: In testng.xml (recommended)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="My Test Suite">
<listeners>
<listener class-name="com.tms.testng.TMSTestNGListener"/>
</listeners>
<test name="Login Tests">
<classes>
<class name="com.example.LoginTest"/>
</classes>
</test>
</suite>
Option B: Via annotation
import com.tms.testng.TMSTestNGListener;
import org.testng.annotations.Listeners;
@Listeners(TMSTestNGListener.class)
public class LoginTest {
// ...
}
Option C: Programmatically
import com.tms.testng.TMSTestNGListener;
import org.testng.TestNG;
TestNG testng = new TestNG();
testng.addListener(new TMSTestNGListener());
testng.setTestClasses(new Class[]{LoginTest.class});
testng.run();
3. Annotate your tests with ProvaLab.io case IDs
import com.tms.testng.TMSTestCase;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
public class LoginTest {
@Test
@TMSTestCase(id = 101)
public void shouldLoginWithValidCredentials() {
boolean result = AuthService.login("[email protected]", "password123");
assertTrue(result, "Login should succeed");
}
@Test
@TMSTestCase(id = 102, priority = "high", testType = "regression")
public void shouldRejectInvalidPassword() {
assertThrows(AuthException.class, () -> {
AuthService.login("[email protected]", "wrong-password");
});
}
@Test
@TMSTestCase(
id = 103,
title = "SSO Login Flow",
priority = "critical",
testType = "e2e",
tags = {"auth", "sso"},
description = "Verify SSO redirect and token exchange"
)
public void shouldLoginWithSSO() {
SSOResult result = AuthService.loginWithSSO("okta");
assertNotNull(result.getToken());
}
}
Run
Maven
mvn test
With testng.xml
mvn test -DsuiteXmlFile=src/test/resources/testng.xml
Gradle
gradle test
You'll see ProvaLab.io output in the console:
========================================
ProvaLab.io TestNG Integration
========================================
Test Run ID: 856
Suite: My Test Suite
Project ID: 12
Organization ID: 1
========================================
[Login Tests]
[PASS] shouldLoginWithValidCredentials (0.12s)
[PASS] shouldRejectInvalidPassword (0.08s)
[FAIL] shouldLoginWithSSO (2.31s)
========================================
ProvaLab.io Test Run Summary
========================================
Test Run ID: 856
Total: 3
Passed: 2
Failed: 1
Skipped: 0
Status: FAILED
========================================
View Results in ProvaLab.io
- Open ProvaLab.io and go to your project
- Click Test Runs in the sidebar
- Find the run named "TestNG: My Test Suite - 2026-02-20 14:30:00"
- Click into it to see individual test results with error details, execution logs, and metadata
The @TMSTestCase Annotation
@TMSTestCase(
id = 456, // Required: ProvaLab.io test case ID
title = "User Login with SSO", // Optional: display name
priority = "critical", // Optional: critical, high, medium, low
testType = "smoke", // Optional: smoke, regression, e2e, unit
tags = {"auth", "sso"}, // Optional: categorization tags
description = "Verify SSO login flow", // Optional: test description
componentId = 5, // Optional: ProvaLab.io component ID
expectedDurationSeconds = 30, // Optional: expected runtime
automated = true // Optional: is this automated? (default: true)
)
Advanced Configuration
DataProvider support
The listener handles @DataProvider iterations, creating separate ProvaLab.io results for each:
@DataProvider(name = "loginData")
public Object[][] loginData() {
return new Object[][] {
{"[email protected]", "admin123", true},
{"[email protected]", "user123", true},
{"[email protected]", "wrong", false},
};
}
@Test(dataProvider = "loginData")
@TMSTestCase(id = 201)
public void shouldHandleLogin(String email, String password, boolean expected) {
assertEquals(AuthService.login(email, password), expected);
}
Each iteration appears as a separate result in ProvaLab.io, with the parameters shown in the test name.
Test case mapping file
Instead of annotations, you can use a JSON mapping file:
{
"com.example.LoginTest": {
"shouldLoginWithValidCredentials": { "id": 101, "priority": "high" },
"shouldRejectInvalidPassword": { "id": 102, "priority": "medium" }
}
}
export TMS_MAPPING_FILE=test-case-mapping.json
WebDriver integration
If tests use Selenium WebDriver, the listener automatically captures screenshots, network logs, and browser type:
import com.tms.testng.TMSTestContextManager;
public class UITest {
private WebDriver driver;
@BeforeMethod
public void setup() {
driver = new ChromeDriver();
// Register the driver with ProvaLab.io for auto-capture
TMSTestContextManager.getCurrentContext().setWebDriver(driver);
}
@AfterMethod
public void teardown() {
if (driver != null) driver.quit();
}
}
Log capture
The listener installs a java.util.logging handler that forwards application logs to ProvaLab.io. These appear in the "Execution Logs" tab for each test result.
Disable ProvaLab.io for local development
export TMS_DISABLED=true
mvn test
Custom test run name
export TMS_TEST_RUN_NAME="Nightly Regression - TestNG"
Verify It Works
- Add the dependency and configure
testng.xml - Set your environment variables
- Create a simple test:
import com.tms.testng.TMSTestCase;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
public class TMSVerifyTest {
@Test
@TMSTestCase(id = 1)
public void verifyTmsIntegration() {
assertEquals(1 + 1, 2, "ProvaLab.io integration working");
}
}
- Run:
mvn test -Dtest=TMSVerifyTest - Check the console for the ProvaLab.io summary
- Open ProvaLab.io and confirm the test run appears
- "Not configured" message: Make sure
TMS_API_KEY,TMS_ORGANIZATION_ID, andTMS_PROJECT_IDenvironment variables are set - Listener not running: Verify the listener is registered in
testng.xmlor via@Listeners - Health check warning: The "ProvaLab.io health check failed" warning is non-fatal -- results are still reported