Behaviour-Driven Development (BDD)
Also Known As
BDD
Gherkin
Behat
Given-When-Then
TL;DR
A development practice where tests are written in business-readable language (Given/When/Then) that domain experts, developers, and testers all understand.
Explanation
BDD extends TDD by making tests readable to non-technical stakeholders. The Given-When-Then structure (Gherkin syntax) describes behaviour: Given a context, When an action occurs, Then an outcome is expected. In PHP, Behat is the primary BDD framework. The value is not the syntax but the conversation it forces — writing in Gherkin requires alignment on what the system should actually do before anyone writes code.
Diagram
sequenceDiagram
participant PO as Product Owner
participant DEV as Developer
participant QA as QA
PO->>DEV: User story
DEV->>DEV: Write Gherkin scenario
Note over DEV: Given user is logged in<br/>When they add item to cart<br/>Then cart count increases
DEV->>QA: Review scenario
QA-->>DEV: Approved
DEV->>DEV: Implement step definitions
DEV->>DEV: Run Behat - fails
DEV->>DEV: Implement feature
DEV->>DEV: Run Behat - passes
Note over DEV,QA: Scenario = living documentation
Common Misconception
✗ BDD is just TDD with different syntax — BDD's primary value is the collaboration and shared vocabulary it creates, not the test format itself.
Why It Matters
BDD scenarios catch misunderstandings between what the business wants and what developers build before code is written, not after it ships.
Common Mistakes
- Writing BDD scenarios for technical implementation details instead of business behaviour.
- Not involving domain experts in writing scenarios — Gherkin written only by developers defeats the purpose.
- Too many steps in a scenario — each scenario should test one behaviour; multiple behaviours need multiple scenarios.
- Using BDD for unit tests — BDD is for business-facing acceptance criteria, not internal implementation testing.
Code Examples
✗ Vulnerable
# BDD scenario testing implementation, not behaviour:
Scenario: Test the UserRepository::findByEmail method
Given the database has a users table
When I call UserRepository::findByEmail('alice@example.com')
Then the PDOStatement should return one row
# This tests a method, not a business behaviour
✓ Fixed
# BDD scenario testing business behaviour:
Feature: User authentication
Scenario: Registered user logs in with correct credentials
Given a user exists with email 'alice@example.com' and password 'secret'
When Alice submits the login form with correct credentials
Then she should be redirected to the dashboard
And she should see a welcome message
Scenario: Wrong password is rejected
Given a user exists with email 'alice@example.com'
When Alice submits the login form with the wrong password
Then she should see an error message
And she should remain on the login page
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
15 Mar 2026
Edited
22 Mar 2026
Views
24
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Perplexity 8
Amazonbot 6
Unknown AI 2
Google 1
Ahrefs 1
Also referenced
How they use it
crawler 18
Related categories
⚡
DEV INTEL
Tools & Severity
🔵 Info
⚙ Fix effort: High
⚡ Quick Fix
Write Behat scenarios in business language before writing PHP code — the scenario describes behaviour from the user's perspective, not the implementation
📦 Applies To
PHP 5.0+
web
cli
🔗 Prerequisites
🔍 Detection Hints
Test descriptions referencing implementation details instead of business behaviour; no Gherkin feature files in project
Auto-detectable:
✗ No
behat
phpspec
codeception
⚠ Related Problems
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: High
Context: File
Tests: Update