Testing / Cucumber Interview Questions
What is the difference between Scenario and Rule in Cucumber's Gherkin?
Scenario is the standard, most commonly used container for a single test case. Rule is a newer Gherkin keyword that groups multiple related scenarios together under a single business rule being illustrated, giving that group its own optional Background distinct from the feature-level one.
Feature: refund policy Rule: refunds are allowed within 30 days of purchase Background: Given a purchase was made 10 days ago Example: refund within the window succeeds When the customer requests a refund Then the refund should be approved Rule: refunds are denied after 30 days Background: Given a purchase was made 45 days ago Example: refund outside the window is denied When the customer requests a refund Then the refund should be denied
Rule is most useful when a single feature genuinely contains multiple distinct business rules, each with several illustrating examples and its own specific setup, since without Rule, that structure either has to be flattened into one shared Background that doesn't cleanly fit every scenario, or split across several separate feature files that arguably belong together conceptually. Note that inside a Rule, individual test cases are conventionally written using the Example keyword, a synonym for Scenario that reads slightly more naturally in this context.
More Related questions...