What is Behavior-Driven Development
Development based on behavior specifications
BDD (Behavior-Driven Development)
BDD is a software development methodology that combines TDD with system behavior descriptions in business-readable language.
Given/When/Then Syntax
| Keyword | Purpose | Example | |---------|---------|---------| | Given | Initial state | Given an authenticated user | | When | Action | When they click "Buy" | | Then | Expected result | Then item is added to cart | | And | Additional conditions | And notification is shown |
Scenario Example (Gherkin)
Feature: Shopping Cart
Scenario: Adding item to cart
Given user is on product page
And item is in stock
When user clicks "Add to Cart"
Then item appears in cart
And cart counter increases by 1
BDD vs TDD
| Aspect | TDD | BDD | |--------|-----|-----| | Focus | Code and units | System behavior | | Language | Technical | Business language | | Participants | Developers | Team + business | | Documentation | Tests as code | Living documentation |
Popular Tools
- Cucumber — Ruby, Java, JS
- SpecFlow — .NET
- Behave — Python
- Jest + Cucumber — JavaScript
- Behat — PHP