Skip to content

Behavior-Driven Development (BDD)

In one line

BDD uses natural language (Given-When-Then) to describe expected behavior, making tests readable by non-technical people.

In simple words

BDD takes TDD and makes it more collaborative. Instead of technical test names, BDD uses a natural language format that everyone — developers, testers, product owners — can understand.

The format is Given-When-Then:

  • Given some initial state (preconditions)
  • When something happens (the action)
  • Then this should result (expected outcome)

For example: 'Given a user is logged in, When they click logout, Then they should see the login page.' This reads like a specification, not a test. The business team can read and validate these scenarios, and developers write code to make them pass.

Tools like Cucumber and Jest-Cucumber execute these natural language scenarios as actual tests.

Example

javascript
// BDD scenario (Cucumber/Gherkin syntax)
Given('a user is logged in', () => { /* setup */ });
When('they click logout', () => { /* action */ });
Then('they should see the login page', () => {
  expect(page.url()).toContain('/login');
});

The Given-When-Then format makes the test readable as a behavior specification.

Common confusions

  • Confused with: TDD

    The difference: BDD focuses on behavior description in natural language for collaboration; TDD focuses on test-first coding practice.

Related terms

Related Resources

Related Lessons

  • BDD

    Behavior-driven development.

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary