JUnit 5 Integration
Run your JUnit 5 tests as usual and have results automatically reported to ProvaLab.io. The SDK provides a JUnit extension that hooks into the test lifecycle and sends results with rich metadata.
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'
testImplementation("com.tms:tms-java-sdk:2.0.0")
Requirements: Java 17+, JUnit 5.10+
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. Add the ProvaLab.io extension to your test class
import com.tms.junit.TMSJUnitExtension;
import com.tms.junit.TMSTestCase;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(TMSJUnitExtension.class)
class LoginTest {
@Test
@TMSTestCase(id = 101)
void shouldLoginWithValidCredentials() {
boolean result = AuthService.login("[email protected]", "password123");
assertTrue(result, "Login should succeed with valid credentials");
}
@Test
@TMSTestCase(id = 102, priority = "high", testType = "regression")
void shouldRejectInvalidPassword() {
assertThrows(AuthException.class, () -> {
AuthService.login("[email protected]", "wrong-password");
});
}
@Test
@TMSTestCase(id = 103, priority = "medium", tags = {"auth", "edge-case"})
void shouldHandleExpiredAccount() {
assertThrows(AccountExpiredException.class, () -> {
AuthService.login("[email protected]", "password123");
});
}
}
3. (Alternative) Register globally via ServiceLoader
Instead of adding @ExtendWith to every class, register the extension globally:
Create src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension:
com.tms.junit.TMSJUnitExtension
Then enable auto-detection in your build:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<configurationParameters>
junit.jupiter.extensions.autodetection.enabled=true
</configurationParameters>
</properties>
</configuration>
</plugin>
Now all test classes automatically report to ProvaLab.io without @ExtendWith.
Run
Maven
mvn test
Gradle
gradle test
You'll see ProvaLab.io output in the console:
ProvaLab.io JUnit Extension
Test Run Created: ID 855
Running: LoginTest
PASS shouldLoginWithValidCredentials (0.12s)
PASS shouldRejectInvalidPassword (0.08s)
FAIL shouldHandleExpiredAccount (0.15s)
ProvaLab.io Results Summary
Test Run ID: 855
Total: 3
Passed: 2
Failed: 1
Skipped: 0
View Results in ProvaLab.io
- Open ProvaLab.io and go to your project
- Click Test Runs in the sidebar
- Find the run named "JUnit: LoginTest"
- Click into it to see individual test results with error details and metadata
The @TMSTestCase Annotation
The annotation supports rich metadata that appears in ProvaLab.io:
@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", "critical"}, // 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)
)
All metadata is pushed to ProvaLab.io and appears in the test result detail view.
Advanced Configuration
Pass environment variables via Maven
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<environmentVariables>
<TMS_API_KEY>${env.TMS_API_KEY}</TMS_API_KEY>
<TMS_API_URL>https://tms.yourcompany.com</TMS_API_URL>
<TMS_ORGANIZATION_ID>1</TMS_ORGANIZATION_ID>
<TMS_PROJECT_ID>12</TMS_PROJECT_ID>
</environmentVariables>
</configuration>
</plugin>
Pass environment variables via Gradle
test {
environment 'TMS_API_KEY', System.getenv('TMS_API_KEY')
environment 'TMS_API_URL', 'https://tms.yourcompany.com'
environment 'TMS_ORGANIZATION_ID', '1'
environment 'TMS_PROJECT_ID', '12'
}
Disable ProvaLab.io for local development
export TMS_DISABLED=true
mvn test
Custom test run name
export TMS_TEST_RUN_NAME="Nightly Regression - JUnit"
Test case ID in test name
If you prefer not to use annotations, you can include [TMS-123] in the display name:
@Test
@DisplayName("[TMS-101] Should login with valid credentials")
void testLogin() {
// The extension extracts TMS-101 from the display name
}
Verify It Works
- Add the dependency to your project
- Set your environment variables
- Create a simple test:
import com.tms.junit.TMSJUnitExtension;
import com.tms.junit.TMSTestCase;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(TMSJUnitExtension.class)
class TMSVerifyTest {
@Test
@TMSTestCase(id = 1)
void verifyTmsIntegration() {
assertEquals(2, 1 + 1, "ProvaLab.io integration working");
}
}
- Run:
mvn test -Dtest=TMSVerifyTestorgradle test --tests 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_IDare all set as environment variables - Extension not running: Check that
@ExtendWith(TMSJUnitExtension.class)is on the class or global auto-detection is enabled - Java version error: The SDK requires Java 17+. Check with
java -version