</>

Technology

Cucumber

Difficulty

Beginner

Interview Question

What is the use of the features property under @CucumberOptions?

Answer

features Property in @CucumberOptions

Purpose

The features property tells the Cucumber framework where to find the .feature files that contain Gherkin scenarios. Without this, Cucumber does not know which scenarios to execute.

Syntax

Java
@CucumberOptions(
    features = "src/test/resources/features"
)

Supported Path Formats

Java
// Single directory — all .feature files inside
features = "src/test/resources/features"

// Specific feature file
features = "src/test/resources/features/login.feature"

// Multiple locations (array)
features = {
    "src/test/resources/features/login",
    "src/test/resources/features/checkout"
}

// Specific scenario by line number
features = "src/test/resources/features/login.feature:15"

// Classpath (when resources are in classpath)
features = "classpath:features"

Directory Scanning

When you provide a directory path, Cucumber recursively scans all subdirectories for .feature files:

CODE
src/test/resources/features/          ← features = "src/test/resources/features"
  login/
    login.feature         ← found
    login_forgot.feature  ← found
  checkout/
    payment.feature       ← found
    shipping.feature      ← found
  cart/
    add_to_cart.feature   ← found

Common Mistakes

Java
// WRONG — path doesn't exist
features = "features"  // relative path might not resolve

// WRONG — missing the full path
features = "resources/features"

// CORRECT
features = "src/test/resources/features"

Override from Maven Command Line

Bash
# Run only smoke features
mvn test -Dcucumber.features="src/test/resources/features/login.feature"

# Run specific scenario (by line number)
mvn test -Dcucumber.features="src/test/resources/features/login.feature:25"

Combined with Tags

Java
@CucumberOptions(
    features = "src/test/resources/features",  // WHERE
    tags = "@smoke"                             // WHICH scenarios
)

Follow AutomateQA

Related Topics