What Are Tags in BDD?

Tags are used to group, filter, and control the execution of scenarios or features in BDD. They let you run specific test cases instead of the entire suite.

In Cucumber, tags are special keywords starting with @ (like @smoke, @regression).

Analogy from your notes: Like using labels such as Urgent, Optional, or Finance to organize files — or running only @smoke tests during deployment instead of full regression.

Advertisement

Where Tags Are Used

Tags can be applied at two levels — Feature level and Scenario / Scenario Outline level — and are mainly used for:

  • Selective test execution (smoke, regression, sanity).
  • Environment-based execution (dev, qa, prod).
  • Role-based flows (admin, user).
  • Hook control using @Before and @After.

In real projects, tags save time, improve test management, and help in CI/CD pipelines.

Real project: "In our retail project, we used @smoke for deployment checks and @regression for full suite execution."


Running Scenarios Using Tags

You run tagged scenarios in two main ways:

Using the Runner File

Specify the required tag in the @CucumberOptions of the runner class.

Using the Command Line / CI Pipeline

Tags are passed as execution parameters.

Only scenarios matching the tag are executed, which is what enables selective test execution.

In real projects, tags are heavily used in Jenkins pipelines to control smoke, sanity, and regression runs.

Real project: "In our banking project, we ran @smoke tests after every deployment and @regression nightly."

The impact: "Execution time reduced and faster feedback was achieved."

Runner File Shape

 
@CucumberOptions(
    features = "src/test/resources/features",
    glue = "stepDefinitions",
    tags = "@smoke"
)
 

Tagging Levels: Feature, Scenario, Scenario Outline

Yes — tags can be applied at Feature, Scenario, and Scenario Outline levels.

Feature Level Tag

Written above the Feature keyword.

  • Applies to all scenarios inside the feature.
  • Used for module-wise execution.

Scenario Level Tag

Written above a Scenario or Scenario Outline.

  • Applies only to that scenario.
  • Used for specific test cases.

Scenario Outline Tag

The tag applies to all example rows of that outline.

So Feature-level tags drive module-wide runs, while scenario-level tags target individual cases — and you can combine them (e.g., @smoke at Feature level with @regression on specific scenarios).

Tagging Shape

 
@login
Feature: Login Functionality

  @smoke
  Scenario: Valid login
    Given User is on the login page
    ...

  @regression
  Scenario Outline: Invalid login
    ...
    Examples:
      | username | password |
 

FAQs

What Are Tags in BDD?

@-prefixed keywords that group and filter scenarios so you can run specific sets (e.g., @smoke) instead of the full suite.

What Are Tags Used For?

Selective execution (smoke/regression/sanity), environment-based runs, role-based flows, and hook control via @Before/@After.

How Do You Run Scenarios by Tag?

Specify the tag in the runner's @CucumberOptions, or pass it on the command line / in a CI pipeline; only matching scenarios run.

Can You Tag Features, Scenarios, and Scenario Outlines?

Yes — Feature-level tags apply to all scenarios, Scenario-level tags apply to that scenario only, and a Scenario Outline tag applies to all its example rows.

How Are Tags Used in CI/CD?

In Jenkins pipelines to control which suite runs — e.g., @smoke after each deployment and @regression nightly.