# Behavior Driven Development

> Behavior-Driven Development

- Skill: `ffsshhttiikk/behavior-driven-development` (Agent Skill)
- Install (CLI): `npx skillmds@latest add ffsshhttiikk/behavior-driven-development`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ffsshhttiikk/behavior-driven-development/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: ffsshhttiikk (https://skillmd.com/u/ffsshhttiikk)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/ffsshhttiikk/behavior-driven-development

---

# Behavior-Driven Development

**Category:** Testing  
**Skill Level:** Intermediate  
**Domain:** Test Automation, Specification by Example, Agile Development

## Overview

Behavior-Driven Development (BDD) is a software development methodology that emphasizes collaboration between technical and non-technical stakeholders to define and verify system behavior through human-readable specifications. It extends Test-Driven Development by focusing on the expected behavior of the system from the user's perspective.

## Description

Behavior-Driven Development emerged as a response to the communication gap that often exists between developers, testers, business analysts, and product owners during software projects. By using a ubiquitous language that everyone can understand, BDD ensures that requirements are unambiguous, testable, and serve as both documentation and executable specifications. The approach bridges the gap between technical implementation and business value by framing tests in terms of user stories and acceptance criteria.

The core BDD workflow begins with collaborative specification writing, typically using a structured format like Gherkin, which describes scenarios in plain language with Given-When-Then syntax. These specifications become the source of truth for expected behavior, guiding development through the Red-Green-Refactor cycle while serving as living documentation for the codebase. Tools like Cucumber, Behave, and SpecFlow parse these specifications and connect them to executable test code that validates system behavior.

BDD promotes the outside-in development approach, where teams define the desired behavior first, then implement just enough code to satisfy the specifications. This prevents over-engineering and ensures that development effort directly addresses business needs. The specifications serve multiple purposes: they guide development, they become regression tests, and they document the system's intended behavior for future maintainers and stakeholders.

Successful BDD implementation requires buy-in from all team members and ongoing maintenance of specifications as requirements evolve. The practice encourages continuous refinement of scenarios, elimination of ambiguity, and shared ownership of quality. When done well, BDD reduces defects discovered late in development cycles, improves team communication, and produces reliable, well-documented software that accurately reflects stakeholder needs.

## Prerequisites

- Understanding of Test-Driven Development principles
- Familiarity with Agile methodologies and user story writing
- Knowledge of testing concepts (unit tests, integration tests)
- Experience with domain modeling and business requirement analysis

## Core Competencies

- Writing Gherkin scenarios with Given-When-Then syntax
- Designing scenarios that cover edge cases and boundary conditions
- Implementing step definitions that connect specifications to code
- Creating data tables and scenario outlines for parameterized tests
- Integrating BDD frameworks into CI/CD pipelines
- Maintaining living documentation through executable specifications

## Implementation

```gherkin
Feature: User Authentication
  As a registered user
  I want to log into my account
  So that I can access my personalized content

  Background:
    Given the user registration service is available
    And I have a valid user account with credentials:
      | username | password     | email             |
      | johndoe  | SecurePass123| john@example.com |

  Scenario: Successful login with valid credentials
    Given I am on the login page
    When I enter my username "johndoe"
    And I enter my password "SecurePass123"
    And I click the "Login" button
    Then I should be redirected to my dashboard
    And I should see a welcome message "Welcome back, John!"

  Scenario: Failed login with invalid password
    Given I am on the login page
    When I enter my username "johndoe"
    And I enter an incorrect password "WrongPassword"
    And I click the "Login" button
    Then I should see an error message "Invalid username or password"

  Scenario Outline: Login with various credential combinations
    Given I am on the login page
    When I enter username "<username>"
    And I enter password "<password>"
    And I click the "Login" button
    Then I should see "<expected_message>"

    Examples:
      | username | password     | expected_message              |
      | johndoe  | SecurePass123| Welcome back, John!           |
      | unknown  | anypassword  | User not found                |
```

```python
from behave import given, when, then
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

@given('I am on the login page')
def step_impl(context):
    context.driver.get("https://example.com/login")

@when('I enter my username "{username}"')
def step_impl(context, username):
    username_field = context.driver.find_element(By.ID, "username")
    username_field.clear()
    username_field.send_keys(username)

@when('I enter my password "{password}"')
def step_impl(context, password):
    password_field = context.driver.find_element(By.ID, "password")
    password_field.clear()
    password_field.send_keys(password)

@when('I click the "{button_text}" button')
def step_impl(context, button_text):
    button = WebDriverWait(context.driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, f"//button[text()='{button_text}']"))
    )
    button.click()

@then('I should be redirected to my dashboard')
def step_impl(context):
    WebDriverWait(context.driver, 10).until(
        EC.url_contains("/dashboard")
    )
    assert "/dashboard" in context.driver.current_url

@then('I should see a welcome message "{message}"')
def step_impl(context, message):
    welcome_element = WebDriverWait(context.driver, 10).until(
        EC.presence_of_element_located((By.CLASS_NAME, "welcome-message"))
    )
    assert welcome_element.text == message

@then('I should see an error message "{error_message}"')
def step_impl(context, error_message):
    error_element = WebDriverWait(context.driver, 5).until(
        EC.presence_of_element_located((By.CLASS_NAME, "error-message"))
    )
    assert error_message in error_element.text
```

## Use Cases

- Defining acceptance criteria collaboratively with product owners
- Creating executable documentation for system behavior
- Automating regression testing for critical user journeys
- Bridging communication gaps between technical and business teams
- Ensuring features meet business requirements before release
- Documenting edge cases and error handling behavior

## Artifacts

- Feature files written in Gherkin syntax
- Step definition implementations for various frameworks
- Page object models for web UI testing
- BDD test reports and living documentation
- CI/CD pipeline configurations for automated BDD tests

## Related Skills

- Test-Driven Development
- Acceptance Testing
- Gherkin Syntax
- Selenium/Playwright Automation
- Specification by Example

