Cucumber
This guide shows how to link Cucumber scenarios to requirements with tags and enforce a coverage gate. Cucumber support was added in 0.0.11.
Add the dependencies
Section titled “Add the dependencies”ReqCover works with Cucumber 7 and 8 (tested with 7.31.0 and 8.0.4) and uses your project’s Cucumber version; it does not bring Cucumber with it.
Gradle (Kotlin DSL), with the GitHub Packages repository from Installation:
dependencies { testImplementation("dev.reqcover:reqcover-engine-cucumber: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")}Maven:
<dependency> <groupId>dev.reqcover</groupId> <artifactId>reqcover-engine-cucumber-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.
Register the plugin
Section titled “Register the plugin”Unlike the JUnit and TestNG engines, the Cucumber engine is a Cucumber plugin and must be registered:
cucumber.plugin=dev.reqcover.cucumber.RequirementsCoverageListenerPut this line in src/test/resources/junit-platform.properties when you run Cucumber on the JUnit Platform, or in src/test/resources/cucumber.properties otherwise.
If you already use other plugins, separate them with commas.
Configure ReqCover
Section titled “Configure ReqCover”Add the ReqCover settings next to the plugin:
cucumber.plugin=dev.reqcover.cucumber.RequirementsCoverageListenerreqCover.requirementsUris=requirements.yamlreqCover.minimumRequiredCoveragePercent=100Settings are looked up in this order; the first place that sets a key wins:
- JVM system property
cucumber.propertieson the test classpathjunit-platform.propertieson the test classpath- Default
Tag scenarios
Section titled “Tag scenarios”A passing scenario covers every requirement it is tagged with. The default tag format is @req:<requirement id>:
@req:#getUsers/200Feature: Users
Scenario: list all users When I list the users Then I see all users
Rule: Missing users
@req:#getUsers/404 Scenario: no users Given there are no users When I list the users Then I get "not found"Tags on a feature or rule apply to all scenarios inside it. In this example, “no users” covers both #getUsers/200 and #getUsers/404.
Scenarios that fail, are skipped, pending or undefined do not cover anything. For a scenario outline, each example row is its own scenario.
Change the tag prefix
Section titled “Change the tag prefix”Set reqCover.cucumber.tagPrefix to use a different prefix. Everything after the prefix is the requirement ID.
reqCover.cucumber.tagPrefix=@requirement=@requirement=#getUsers/200Scenario: list all usersRun on the JUnit Platform
Section titled “Run on the JUnit Platform”A typical setup with cucumber-junit-platform-engine and the JUnit Platform Suite:
dependencies { testImplementation(platform("io.cucumber:cucumber-bom:8.0.4")) testImplementation(platform("org.junit:junit-bom:6.1.3")) testImplementation("io.cucumber:cucumber-java") testImplementation("io.cucumber:cucumber-junit-platform-engine") testImplementation("org.junit.platform:junit-platform-suite") testRuntimeOnly("org.junit.platform:junit-platform-launcher") testImplementation("dev.reqcover:reqcover-engine-cucumber:0.0.12") testImplementation("dev.reqcover:reqcover-source-openapi:0.0.12") testImplementation("dev.reqcover:reqcover-reporter-html:0.0.12")}
tasks.test { useJUnitPlatform()}Use your own Cucumber version in the BOM.
import org.junit.platform.suite.api.IncludeEngines;import org.junit.platform.suite.api.SelectClasspathResource;import org.junit.platform.suite.api.Suite;
@Suite@IncludeEngines("cucumber")@SelectClasspathResource("features")public class CucumberTest {}src/test/resources/junit-platform.properties:
cucumber.plugin=dev.reqcover.cucumber.RequirementsCoverageListenercucumber.glue=example.stepsreqCover.requirementsUris=requirements.yamlreqCover.minimumRequiredCoveragePercent=100