← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Behaviour-Driven Development (BDD)

Testing PHP 5.0+ Intermediate
debt(d7/e5/b3/t6)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7), because misuse of BDD (scenarios describing implementation details, no domain expert involvement) is not catchable by Behat/phpSpec/Codeception themselves — they happily run technically-correct but business-irrelevant scenarios. Detection requires human review of feature files.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5), because rewriting feature files to reflect business behaviour means rewriting scenarios, step definitions, and often involving stakeholders — more than a parameterised swap but localised to the test suite.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3), because BDD scenarios live in a features/ directory and affect the testing workflow but don't shape production code architecture; applies_to covers web/cli but the burden is concentrated in the acceptance test layer.

t6 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t6), slightly below t7 because the misconception ('BDD is just TDD with different syntax') leads developers to adopt the tooling without the collaboration practice, missing the entire point — a notable contradiction with how the name suggests it works, but not catastrophic since the tests still provide some value.

About DEBT scoring →

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

Added 15 Mar 2026
Edited 22 Mar 2026
Views 49
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 3 pings S 1 ping S 0 pings M 2 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 1 ping S 1 ping M 1 ping T 0 pings W
No pings yet today
PetalBot 1
Perplexity 8 Amazonbot 7 Scrapy 6 Ahrefs 4 Google 3 Unknown AI 2 Claude 2 ChatGPT 2 PetalBot 2 SEMrush 1 Meta AI 1 Bing 1
crawler 36 crawler_json 3
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


✓ schema.org compliant