Behavior-Driven Development

BDD stands for Behavior-Driven Development — it’s an evolution of TDD (Test-Driven Development) that focuses on how the software should behave from the user’s point of view.

Instead of writing tests in a technical way, BDD describes them in natural, human-readable language — usually using the Given–When–Then format.


💡 Simple Example

Let’s say we’re building a login feature.

BDD Scenario (in plain English):

Feature: User Login

Scenario: Successful login
  Given the user is on the login page
  When the user enters valid credentials
  Then the user should be redirected to the dashboard

This describes behavior, not implementation details.


🧩 Example in Code (Python + Behave)

# features/login.feature
Feature: User Login
  Scenario: Successful login
    Given the user is on the login page
    When the user enters valid credentials
    Then the user should see the dashboard
# features/steps/login_steps.py
from behave import given, when, then

@given('the user is on the login page')
def step_user_on_login_page(context):
    context.page = "login"

@when('the user enters valid credentials')
def step_user_enters_credentials(context):
    context.logged_in = True

@then('the user should see the dashboard')
def step_user_sees_dashboard(context):
    assert context.logged_in is True

✅ In Short

ConceptTDDBDD
FocusCode correctnessUser behavior
LanguageTechnical (unit tests)Natural (Given–When–Then)
GoalMake code workMake behavior right

Leave a Reply