Skip to main content

Tags

Gherkin tags (@smoke, @regression, …) map to JUnit @Tag annotations for selective test execution.

Source: examples/getting-started/example-7 on GitHub.

What this demonstrates

  • Feature-level tags → @Tag on the generated outer test class
  • Rule-level tags → @Tag on the @Nested rule class
  • Scenario-level tags → @Tag on the @Test method
  • Multiple tags → wrapped in a @Tags container annotation
  • Tags enable filtering in IDEs, Maven Surefire, and CI pipelines

Gherkin → JUnit mapping

GherkinJUnit
@cart @regression on a Feature@Tags({@Tag("cart"), @Tag("regression")}) on outer class
@ui @shipping on a Rule@Tags({@Tag("ui"), @Tag("shipping")}) on @Nested class
@smoke on a Scenario@Tag("smoke") on @Test method
@smoke @happy-path on a Scenario@Tags({@Tag("smoke"), @Tag("happy-path")}) on @Test method

Running filtered tests

IntelliJ IDEA — right-click a tag in the test class → Run tests tagged…

Maven Surefire:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>smoke</groups> <!-- include only @smoke -->
<excludedGroups>edge-case</excludedGroups> <!-- exclude @edge-case -->
</configuration>
</plugin>

GradleuseJUnitPlatform { includeTags 'smoke' }.

Run it

cd examples/getting-started/example-7
mvn test