Write BDD Feature Files
Purpose
Express the expected behavior of a feature as concise Gherkin that business people can read and confirm, and that automation can bind to without rewriting.
When to use
- Acceptance criteria are agreed and the team wants living, executable specifications.
- A three-amigos or refinement session produced examples that need to be written down.
- Existing feature files are long click-by-click scripts that break on every UI change.
When not to use
- The behavior itself is not yet agreed. Use
acceptance-criteria to settle the rules first.
- You need detailed manual steps with per-step expected results. Use
test-case-writing.
- You need the step-definition or automation code. Use
test-automation-script.
Inputs
Required:
- The story, acceptance criteria or business rules to specify.
Optional, improves quality:
- Domain glossary and existing step vocabulary, tagging conventions, language setting (
# language: tr if the team writes Gherkin in Turkish).
- Boundaries and examples already discussed with the business.
If no rule or criterion is given, ask for it. Unclear outcomes become scenarios tagged @question with the open point in a comment.
Process
- Extract the rules from the input; each rule becomes a
Rule: block or a group of scenarios. Keep one feature file per capability, not per screen.
- Write the feature header: name plus a short "In order to / As a / I want" or plain narrative stating the business value. Use a specific role, never "a user".
- Put only shared, essential context in
Background; if it is longer than about three steps or not needed by every scenario, move it into the scenarios.
- For each rule write at least one positive and one negative scenario. Title each scenario with the behavior, not the test ("Coupon is rejected when basket is below minimum").
- Write steps declaratively in domain language: Given = state, When = one business action, Then = observable outcome. No clicks, selectors, URLs or technical IDs.
- Keep one When and one Then per scenario (And under Then only for facets of the same outcome); multiple actions or outcomes mean split the scenario.
- Use
Scenario Outline with Examples for data variations of the same behavior, choosing rows from equivalence classes and boundaries; do not use outlines to hide different behaviors.
- Reuse existing step phrasing where given so step definitions stay small; keep wording consistent (same noun for the same concept).
- Add tags for traceability and execution (
@REQ-123, @smoke, @wip, @question) according to team convention.
- Label any inferred rule
[ASSUMPTION] in a comment and list open questions below the file.
- If the user continues, suggest
test-automation-script for step definitions or acceptance-criteria when open questions change the rules.
Output format
@<capability-tag> @<REQ-id>
Feature: <capability>
<business value narrative with a specific role>
Background:
Given <shared essential context>
Rule: <business rule>
Scenario: <behavior in one sentence>
Given <state>
When <one business action>
Then <observable outcome>
Scenario Outline: <behavior varying by data>
Given <state with <param>>
When <action>
Then <outcome with <result>>
Examples:
| param | result |
Open questions / assumptions: numbered list below the file.
Quality checklist
Common pitfalls
- Imperative scripts ("When I click Apply, And I type ..."). They couple to the UI and hide the rule; describe intent instead.
- Huge Background sections that every reader must scroll past. Keep only what all scenarios need.
- One Scenario Outline with a column that switches between completely different behaviors. Split into separate scenarios.
- Writing Gherkin after automation as documentation of test code. The value comes from agreeing examples before building.
Example
Input: "One coupon per order, minimum basket 250 TL, not combinable with campaign prices, expired coupons rejected."
Weak:
Scenario: coupon test
When I open the basket page and type "SAVE10" into #coupon and click Apply
Then I see a message and the total changes and the second coupon field is disabled
Strong (excerpt):
Rule: The basket must reach the minimum amount
Scenario Outline: Coupon acceptance depends on basket total
Given a customer's basket totals <total> TL
When the customer applies a valid coupon
Then the coupon is <result>
Examples:
| total | result |
| 249.99 | rejected |
| 250.00 | accepted |
Open question: Is the minimum checked before or after campaign discounts? [ASSUMPTION: before]
1---2name: bdd-feature-file3description: "Writes Gherkin feature files with a business-readable feature description, background, declarative scenarios and scenario outlines with example tables, tagged and traceable to requirements. Use when a team practices behavior-driven development or specification by example, when acceptance criteria must become executable specifications, or when existing Gherkin is imperative, UI-bound or hard to maintain."4license: MIT5metadata:6 source: https://skillmd.com/skills/muratdincer/bdd-feature-file7 version: "1.0.0"8 language: en9 category: 06-quality10 role: qa-analyst11 area: design12 title: "Write BDD feature files"13 related: "acceptance-criteria, user-story, test-scenarios-from-requirements, test-automation-script, equivalence-boundary-analysis"14 prompt: "Write a feature file for the coupon rule: one coupon per order, minimum basket 250 TL, not combinable with campaign prices, expired coupons rejected."15---1617# Write BDD Feature Files1819## Purpose20Express the expected behavior of a feature as concise Gherkin that business people can read and confirm, and that automation can bind to without rewriting.2122## When to use23- Acceptance criteria are agreed and the team wants living, executable specifications.24- A three-amigos or refinement session produced examples that need to be written down.25- Existing feature files are long click-by-click scripts that break on every UI change.2627## When not to use28- The behavior itself is not yet agreed. Use `acceptance-criteria` to settle the rules first.29- You need detailed manual steps with per-step expected results. Use `test-case-writing`.30- You need the step-definition or automation code. Use `test-automation-script`.3132## Inputs33Required:34- The story, acceptance criteria or business rules to specify.3536Optional, improves quality:37- Domain glossary and existing step vocabulary, tagging conventions, language setting (`# language: tr` if the team writes Gherkin in Turkish).38- Boundaries and examples already discussed with the business.3940If no rule or criterion is given, ask for it. Unclear outcomes become scenarios tagged `@question` with the open point in a comment.4142## Process431. Extract the rules from the input; each rule becomes a `Rule:` block or a group of scenarios. Keep one feature file per capability, not per screen.442. Write the feature header: name plus a short "In order to / As a / I want" or plain narrative stating the business value. Use a specific role, never "a user".453. Put only shared, essential context in `Background`; if it is longer than about three steps or not needed by every scenario, move it into the scenarios.464. For each rule write at least one positive and one negative scenario. Title each scenario with the behavior, not the test ("Coupon is rejected when basket is below minimum").475. Write steps declaratively in domain language: Given = state, When = one business action, Then = observable outcome. No clicks, selectors, URLs or technical IDs.486. Keep one When and one Then per scenario (And under Then only for facets of the same outcome); multiple actions or outcomes mean split the scenario.497. Use `Scenario Outline` with `Examples` for data variations of the same behavior, choosing rows from equivalence classes and boundaries; do not use outlines to hide different behaviors.508. Reuse existing step phrasing where given so step definitions stay small; keep wording consistent (same noun for the same concept).519. Add tags for traceability and execution (`@REQ-123`, `@smoke`, `@wip`, `@question`) according to team convention.5210. Label any inferred rule `[ASSUMPTION]` in a comment and list open questions below the file.5311. If the user continues, suggest `test-automation-script` for step definitions or `acceptance-criteria` when open questions change the rules.5455## Output format56```gherkin57@<capability-tag> @<REQ-id>58Feature: <capability>59 <business value narrative with a specific role>6061 Background:62 Given <shared essential context>6364 Rule: <business rule>6566 Scenario: <behavior in one sentence>67 Given <state>68 When <one business action>69 Then <observable outcome>7071 Scenario Outline: <behavior varying by data>72 Given <state with <param>>73 When <action>74 Then <outcome with <result>>7576 Examples:77 | param | result |78```79Open questions / assumptions: numbered list below the file.8081## Quality checklist82- [ ] A business stakeholder can read every scenario without technical knowledge.83- [ ] Each scenario has exactly one When and one Then outcome; Given describes state, not actions.84- [ ] No UI mechanics, selectors, URLs or database details in steps.85- [ ] Every rule has at least one negative scenario; boundaries appear in Examples.86- [ ] Scenarios are independent and titled by behavior.87- [ ] Tags provide traceability to requirements and inferred rules are marked `[ASSUMPTION]`.88- [ ] All checks pass; if any fails, revise the output and re-run this checklist before answering.8990## Common pitfalls91- Imperative scripts ("When I click Apply, And I type ..."). They couple to the UI and hide the rule; describe intent instead.92- Huge Background sections that every reader must scroll past. Keep only what all scenarios need.93- One Scenario Outline with a column that switches between completely different behaviors. Split into separate scenarios.94- Writing Gherkin after automation as documentation of test code. The value comes from agreeing examples before building.9596## Example97Input: "One coupon per order, minimum basket 250 TL, not combinable with campaign prices, expired coupons rejected."9899Weak:100```gherkin101Scenario: coupon test102 When I open the basket page and type "SAVE10" into #coupon and click Apply103 Then I see a message and the total changes and the second coupon field is disabled104```105Strong (excerpt):106```gherkin107Rule: The basket must reach the minimum amount108109 Scenario Outline: Coupon acceptance depends on basket total110 Given a customer's basket totals <total> TL111 When the customer applies a valid coupon112 Then the coupon is <result>113114 Examples:115 | total | result |116 | 249.99 | rejected |117 | 250.00 | accepted |118```119Open question: Is the minimum checked before or after campaign discounts? `[ASSUMPTION: before]`