← Back to libraryQuestion 259 of 273
🌀Agile & QAIntermediate

Writing Acceptance Criteria & Gherkin (BDD)

📌 Definition:

Behavior-Driven Development (BDD) expresses acceptance criteria as concrete, structured scenarios using the Given-When-Then format (Gherkin). Given sets up context, When is the action, and Then is the expected outcome — a format readable by business and technical people alike and directly convertible into automated tests.

📖 Detailed Explanation:

Gherkin turns fuzzy criteria into precise, example-based specifications. 'Given the cart has an item and a valid code, When the shopper applies the code, Then the total decreases by the discount' is unambiguous, testable, and shared vocabulary across PO, developers and QA. This shared language is BDD's real value: it aligns everyone on behavior before code is written, reducing the misunderstandings that cause defects. Scenarios also map one-to-one to automated acceptance tests (e.g. via Cucumber/SpecFlow/Playwright-BDD), so the specification and the test stay in sync. Good scenarios are concrete (use real example values), focused (one behavior each), and cover negative and edge cases, not just the happy path — which is where QA drives the most value. A caution testers should know: BDD is about collaboration and shared understanding, not merely a test-automation syntax; teams that adopt the Gherkin format without the upfront conversation miss most of the benefit.

🔑 Key Points:
  • Gherkin: Given (context) → When (action) → Then (expected outcome)
  • Readable by business + technical stakeholders — a shared behavior language
  • Aligns everyone on behavior before coding, preventing misunderstanding-driven defects
  • Scenarios map directly to automated acceptance tests, keeping spec and test in sync
  • BDD's value is the collaboration/conversation, not just the syntax
🌍 Real-World Example:

Before coding a login lockout feature, the PO, a developer and QA write Gherkin scenarios together — including the negative case 'Given 5 failed attempts, When I try again, Then the account is locked for 15 minutes'. Writing it together surfaces that nobody had decided the lockout duration, resolving the ambiguity before a line of code is written.

📎 Code Example:
Feature: Account lockout after failed logins

  Scenario: Successful login resets the counter
    Given a user with 2 previous failed attempts
    When they log in with the correct password
    Then they are logged in
    And the failed-attempt counter is reset to 0

  Scenario: Account locks after 5 failed attempts
    Given a user with 4 previous failed attempts
    When they enter an incorrect password
    Then the account is locked for 15 minutes
    And they see "Account locked. Try again in 15 minutes."

  Scenario: Locked account rejects even the correct password
    Given a locked account
    When they enter the correct password within the lockout window
    Then login is refused with the lockout message
🎯 Scenario-Based Interview Question:

Scenario: A team adopts Cucumber and writes Gherkin for every story, but defects from misunderstood requirements keep happening and developers say BDD 'is just extra syntax that slows us down'. What has the team missed about BDD, and how would you fix it?