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 →
@Tagon the generated outer test class - Rule-level tags →
@Tagon the@Nestedrule class - Scenario-level tags →
@Tagon the@Testmethod - Multiple tags → wrapped in a
@Tagscontainer annotation - Tags enable filtering in IDEs, Maven Surefire, and CI pipelines
Gherkin → JUnit mapping
| Gherkin | JUnit |
|---|---|
@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>
Gradle — useJUnitPlatform { includeTags 'smoke' }.
Run it
cd examples/getting-started/example-7
mvn test