Agile Testing

Behavior-Driven Development

An agile testing practice that uses natural language scenarios to describe system behaviour, fostering collaboration between technical and non-technical stakeholders.

Junior Senior Test Lead

What It Is

Behavior-Driven Development (BDD) extends TDD by shifting the focus from technical tests to shared understanding of system behaviour. It uses a structured natural language format, Given-When-Then, to describe how a feature should behave in various scenarios. These scenarios are written collaboratively by developers, testers, and business representatives, ensuring everyone speaks the same language before any code is written.

BDD was popularised by Dan North as a response to the confusion many teams felt when adopting TDD. By framing tests as behaviour specifications rather than unit-test mechanics, BDD makes the practice accessible to product owners, business analysts, and domain experts who may not read code.

The Three Amigos: BDD works best when a developer, a tester, and a business representative discuss scenarios together before implementation. This short workshop surfaces misunderstandings early and produces acceptance criteria that are genuinely shared.

Given-When-Then Format

Each scenario follows a simple structure:

  • Given some initial context or precondition
  • When an action or event occurs
  • Then an expected outcome is observed

This format is concrete enough to be automated, yet readable enough for non-technical stakeholders to validate.

Tip: A good scenario describes what the system does, not how it does it. Avoid references to UI elements, database tables, or API endpoints in the business-facing text.

When to Use It

BDD shines in contexts where clear communication between technical and business teams is critical:

  • Complex domain logic: Insurance, finance, healthcare, and compliance-heavy systems benefit from explicit examples that domain experts can review.
  • Cross-functional teams: When product owners, testers, and developers work closely, BDD provides a shared vocabulary that reduces translation errors.
  • Regulated industries: Scenarios become auditable evidence that requirements were understood and met.
  • Remote or asynchronous teams: Written scenarios replace hallway conversations and serve as durable reference material.
  • Legacy system replacement: BDD scenarios capture existing behaviour so the new system can be validated against it.

BDD may be overhead for simple CRUD applications or internal tools with no external business stakeholder. Use judgment: if no one outside engineering will read the scenarios, lightweight unit tests may suffice.

Key Concepts

Given-When-Then

The structured grammar that makes BDD scenarios predictable and automatable. It separates preconditions, actions, and outcomes so that each scenario has a single, clear purpose. Multiple Givens or Thens are allowed, but each scenario should exercise only one behaviour.

Feature Files

Scenarios are collected in feature files, typically one per major capability. A feature file contains a narrative description (the user story) followed by concrete examples (the scenarios). Tools such as Cucumber, SpecFlow, or Behave parse these files and bind each step to test automation code.

Living Documentation

Because feature files are executed by automated test runners, they stay current. Unlike Word documents or wikis, living documentation cannot drift out of date without the build breaking. This makes it a trustworthy reference for new team members, auditors, and support staff.

Ubiquitous Language

Borrowed from Domain-Driven Design, ubiquitous language means using the same terms in scenarios, code, and conversation. If the business says policyholder, the code should say Policyholder, not User or CustomerEntity. This alignment eliminates the mental translation tax that causes so many bugs.

Concept Description Tool Examples
Feature File Human-readable document containing scenarios for one capability Cucumber .feature, SpecFlow .feature, Behave .feature
Step Definition Code that binds a natural language step to automation logic Cucumber JVM, Cucumber JS, SpecFlow bindings
Scenario Outline Parameterized scenario run against multiple data sets Examples table in Gherkin syntax

Common Pitfalls

Scenarios Too Technical

When scenarios read like API test scripts or SQL queries, business stakeholders stop reading them. If the product owner cannot understand a scenario without a developer translating, the scenario has failed its primary purpose. Keep the language business-oriented and push technical details down into step definitions.

Business Disengaging

BDD depends on active business participation. If scenarios are written solely by testers or developers, they become a slower form of traditional test scripting. Schedule regular Three Amigos sessions and keep scenarios short enough that a business representative can review them in minutes, not hours.

Brittle UI-Focused Scenarios

Scenarios that reference CSS selectors, button IDs, or page layouts break every time the UI changes. BDD should describe behaviour, not presentation. Use page objects, component models, or API bindings to isolate the scenario text from implementation churn.

Anti-pattern: When a single UI change causes twenty feature files to fail, your BDD layer has leaked implementation details. Refactor the automation glue, not the scenarios.

The New Zealand Context

New Zealand software projects often involve non-technical clients in agriculture, government, or small business who need transparent confirmation that their investment is delivering the right outcomes. BDD scenarios provide that transparency in plain English, building trust and reducing the risk of expensive rework.

Many New Zealand teams are distributed across Auckland, Wellington, Christchurch, and remote workers in smaller centres. Written scenarios serve as durable contracts between these locations, reducing the need for repeated clarification calls. They also help when outsourcing or nearshoring parts of development: a well-written feature file is a clearer brief than a user story alone.

Local compliance requirements, such as those from the Privacy Act or sector-specific regulators, can be encoded directly into scenarios. A feature titled Data retention policy ensures personal data is deleted after two years becomes both a requirement and an automated compliance check.

Career Level Guidance

Level Focus Milestones
Junior Write readable Given-When-Then scenarios; implement step definitions; run feature files locally Can translate a user story into 3-5 scenarios; step definitions are clean and reusable; no UI selectors in feature text
Senior Facilitate Three Amigos sessions; design test architecture; keep living documentation current Leads scenario workshops; designs page object / API abstraction layers; reviews feature files for business clarity
Test Lead Define BDD standards; integrate with CI/CD; measure scenario coverage and business engagement Sets organisation-wide BDD conventions; tracks scenario-to-story coverage; trains product owners to write scenarios
Tip for test leads: Measure BDD success by how often business stakeholders reference feature files during planning or support, not by how many scenarios exist. A hundred ignored scenarios is waste; ten actively discussed scenarios is value.
← Back to Agile Techniques Next: Shift-Left Testing →