Skip to content
BENIBIX Learn

Behavior-Driven Development (BDD)

Development🧪 Testing & QualityTest Practices

Also known as BDD, Behaviour-Driven Development, Gherkin, Cucumber (Testing)

Writing features as Given, When, Then lines. The lines also run as tests.

Think of it like

Think of it like writing the rules of a game in plain words first. Then everyone plays it the same way.

Example

Emma runs a shop, and Jack writes the code. They write the checkout rules together as Given, When, Then lines. Jack is done when every line passes.

Why it matters

The people who want the feature and the people who build it agree first. Then nobody codes the wrong thing.

Definition

Behavior-driven development is a way to describe a feature in plain sentences before coding it. Each example is written as Given, When and Then. Given sets the scene, When is the action, and Then is the result. Tools like Cucumber turn these sentences into tests that run. People who do not code can read and agree on them.

Example code

gherkin
Scenario: Pay with a valid card
  Given a cart with one mug
  When I pay with a valid card
  Then I see "Thank you"
One scenario in plain words, which a tool can run as a test.
The scenario card is written Given, When, Then.

Common mistake

Writing scenarios about buttons and clicks. Write what the user wants, not how the screen works.

Key takeaways

  1. 1
    Plain words. Anyone on the team can read it.
  2. 2
    Given, When, Then. Scene, action, result.
  3. 3
    Runs as a test. The sentences are checked.

Compare