Skip to content

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.

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.

Unlike the JUnit and TestNG engines, the Cucumber engine is a Cucumber plugin and must be registered:

cucumber.plugin=dev.reqcover.cucumber.RequirementsCoverageListener

Put 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.

Add the ReqCover settings next to the plugin:

cucumber.plugin=dev.reqcover.cucumber.RequirementsCoverageListener
reqCover.requirementsUris=requirements.yaml
reqCover.minimumRequiredCoveragePercent=100

Settings are looked up in this order; the first place that sets a key wins:

  1. JVM system property
  2. cucumber.properties on the test classpath
  3. junit-platform.properties on the test classpath
  4. Default

A passing scenario covers every requirement it is tagged with. The default tag format is @req:<requirement id>:

@req:#getUsers/200
Feature: 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.

Set reqCover.cucumber.tagPrefix to use a different prefix. Everything after the prefix is the requirement ID.

reqCover.cucumber.tagPrefix=@requirement=
@requirement=#getUsers/200
Scenario: list all users

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.RequirementsCoverageListener
cucumber.glue=example.steps
reqCover.requirementsUris=requirements.yaml
reqCover.minimumRequiredCoveragePercent=100