TestNG
This guide shows how to use ReqCover with TestNG, including testng.xml parameters, several suites and data providers.
Add the dependencies
Section titled “Add the dependencies”Gradle (Kotlin DSL), with the GitHub Packages repository from Installation:
dependencies { testImplementation("dev.reqcover:reqcover-engine-testng:0.0.12") testImplementation("dev.reqcover:reqcover-source-openapi:0.0.12") testImplementation("dev.reqcover:reqcover-reporter-html:0.0.12") testImplementation("dev.reqcover:reqcover-reporter-xml:0.0.12")}
tasks.test { useTestNG()}Maven:
<dependency> <groupId>dev.reqcover</groupId> <artifactId>reqcover-engine-testng-jvm</artifactId> <version>0.0.12</version> <scope>test</scope></dependency>Add the source and reporter -jvm artifacts the same way; see the Maven guide.
Registration
Section titled “Registration”The listener dev.reqcover.testng.RequirementsCoverageListener is registered through META-INF/services/org.testng.ITestNGListener, so TestNG loads it automatically.
You do not need @Listeners or a <listeners> entry in testng.xml.
Configure with system properties
Section titled “Configure with system properties”Gradle:
tasks.test { useTestNG() systemProperty("reqCover.requirementsUris", "requirements.yaml") systemProperty("reqCover.minimumRequiredCoveragePercent", "100")}Maven Surefire:
<systemPropertyVariables> <reqCover.requirementsUris>requirements.yaml</reqCover.requirementsUris> <reqCover.minimumRequiredCoveragePercent>100</reqCover.minimumRequiredCoveragePercent> <reqCover.reportsDir>${project.build.directory}/reqcover</reqCover.reportsDir></systemPropertyVariables>TestNG does not read junit-platform.properties.
Configure with testng.xml
Section titled “Configure with testng.xml”Suite parameters work as well. System properties take precedence over them.
<suite name="Users"> <parameter name="reqCover.requirementsUris" value="requirements.yaml"/> <parameter name="reqCover.minimumRequiredCoveragePercent" value="100"/> <test name="users"> <classes> <class name="example.UsersTest"/> </classes> </test></suite>Several suites
Section titled “Several suites”When a run contains several suites, ReqCover combines their settings:
| Setting | Rule |
|---|---|
reqCover.requirementsUris |
The union of all suites’ URIs; each file is loaded once |
reqCover.minimumRequiredCoveragePercent |
The highest minimum of all suites |
reqCover.failIfBelowMinimum |
The build fails if any suite asks for it; a suite that does not set it counts as true |
reqCover.reportsDir |
Taken from the first suite that sets it |
Annotate tests
Section titled “Annotate tests”Annotate test methods with @ForRequirement, as with JUnit. A passing test covers the requirements of its method.
Since 0.0.12, the annotation can also go on a test class; a passing test then covers the requirements of its method and its class.
Java:
import dev.reqcover.api.ForRequirement;import org.testng.annotations.Test;
public class UsersTest { @Test @ForRequirement(id = "#getUsers/200") public void listsUsers() { }}Kotlin:
import dev.reqcover.api.ForRequirementimport org.testng.annotations.Test
class UsersTest { @Test @ForRequirement("#getUsers/200") fun listsUsers() { }}Data providers
Section titled “Data providers”A test that uses a data provider covers its requirement if at least one invocation passes.
@DataProviderpublic Object[][] names() { return new Object[][] {{"alice"}, {"bob"}};}
@Test(dataProvider = "names")@ForRequirement(id = "#getUser/200")public void findsUser(String name) { }