Skip to content

Maven

This guide shows how to set up ReqCover in a Maven build with the Surefire plugin, for JUnit, TestNG and Cucumber.

ReqCover is on GitHub Packages, not Maven Central. Add the repository to pom.xml:

<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/reqcover/reqcover</url>
</repository>
</repositories>

Add the credentials to ~/.m2/settings.xml. The server id must match the repository id:

<settings>
<servers>
<server>
<id>github</id>
<username>your-github-username</username>
<password>ghp_your_token</password>
</server>
</servers>
</settings>

The token needs the read:packages scope. See Installation.

Maven uses the JVM artifacts, which have a -jvm suffix. Pick the engine for your framework:

Framework Engine artifact
JUnit Jupiter reqcover-engine-junit-jupiter-jvm
TestNG reqcover-engine-testng-jvm
Cucumber reqcover-engine-cucumber-jvm
<properties>
<reqcover.version>0.0.12</reqcover.version>
</properties>
<dependencies>
<dependency>
<groupId>dev.reqcover</groupId>
<artifactId>reqcover-engine-junit-jupiter-jvm</artifactId>
<version>${reqcover.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dev.reqcover</groupId>
<artifactId>reqcover-source-openapi-jvm</artifactId>
<version>${reqcover.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dev.reqcover</groupId>
<artifactId>reqcover-reporter-html-jvm</artifactId>
<version>${reqcover.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dev.reqcover</groupId>
<artifactId>reqcover-reporter-xml-jvm</artifactId>
<version>${reqcover.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Pass the settings as system properties. Always set reqCover.reportsDir:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<reqCover.requirementsUris>requirements.yaml</reqCover.requirementsUris>
<reqCover.minimumRequiredCoveragePercent>100</reqCover.minimumRequiredCoveragePercent>
<reqCover.reportsDir>${project.build.directory}/reqcover</reqCover.reportsDir>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

Put requirements.yaml in src/test/resources; reqCover.requirementsUris is a classpath location.

  • JUnit: the settings can also go in src/test/resources/junit-platform.properties; system properties win. See the JUnit guide.
  • TestNG: the settings can also be testng.xml suite parameters; system properties win. See the TestNG guide.
  • Cucumber: register the plugin with cucumber.plugin=dev.reqcover.cucumber.RequirementsCoverageListener in junit-platform.properties or cucumber.properties. See the Cucumber guide.

When the coverage is below the minimum, ReqCover writes the reports, logs an error and ends the test JVM with exit code 1:

Requirements coverage: 1 out of 2 = 50.0%
Requirements coverage is below the minimum required coverage of 100.0%. Actual coverage: 50.0%
Exiting with error code 1 due to insufficient requirements coverage.

Surefire then reports that the forked VM terminated without properly saying goodbye, and the build fails. The reports in target/reqcover/ show which requirements are missing. To see the coverage without failing the build, set reqCover.failIfBelowMinimum to false.