← Back to libraryQuestion 254 of 468
🥒Cucumber / BDDIntermediate

Tags and Running Tests by Tag

📌 Definition:

Tags (@name) annotate features and scenarios so you can run subsets — e.g. @smoke, @regression, @wip — via tag expressions, controlling what executes in each pipeline stage.

📖 Detailed Explanation:

Place @smoke above a Scenario or Feature, then run only those with a tag expression: --tags '@smoke', or combine with logic: '@smoke and not @wip', '@regression or @critical'. Tags enable smoke tests on every PR and full regression nightly, skipping work-in-progress (@wip) or flaky (@flaky) scenarios. Tags can also drive tagged hooks (@Before('@db')). Feature-level tags apply to all scenarios inside. A consistent tagging strategy (by suite, priority, feature area) is essential for scaling a Cucumber suite and is a common interview/design topic.

🔑 Key Points:
  • @tag on features/scenarios enables selective runs
  • Tag expressions: '@smoke and not @wip', '@a or @b'
  • Feature-level tag applies to all its scenarios
  • Drive tagged hooks + pipeline stages (smoke on PR, full nightly)
🌍 Real-World Example:

CI runs cucumber --tags '@smoke' on pull requests (fast) and the full suite nightly, while @wip scenarios are excluded from CI with 'not @wip' — all controlled by tags without changing code.

🎯 Scenario-Based Interview Question:

You want fast smoke tests on PRs and full regression nightly, excluding work-in-progress scenarios. How do tags achieve this?