World’s largest virtual agentic engineering & quality conference
Learn what BDD testing is, how Given-When-Then scenarios work, and how to write BDD test cases that stay readable, with examples, best practices and tools.

Sanjay Singh
Author

Himanshu Sheth
Reviewer
Published on: November 25, 2025
Last Updated on: August 10, 2026
BDD (Behavior-Driven Development) testing is a way of writing tests as plain-language sentences that describe what a feature should do. Business, development, and testing agree on those sentences before the code is written, using a simple Given-When-Then format. A tool then runs each sentence as an automated test.
BDD exists to remove confusion about what to build, so its value comes from the agreement rather than the tooling. Dan North named the practice in an article published on 20 September 2006, after watching programmers learning test-driven development ask where to start, what to test, and what to call their tests. Teams still adopt the syntax today and skip the conversation behind it.
Key Takeaways
Behavior-Driven Development is an Agile development practice in which developers, testers, and business stakeholders agree on how a feature should behave, express that agreement as plain-language scenarios, and automate those scenarios as acceptance tests.
The Agile Alliance defines BDD as a synthesis and refinement of practices stemming from Test-Driven Development and Acceptance Test-Driven Development, and notes that it is also referred to as Specification by Example.
Three properties separate BDD from writing tests in readable language:
That third property is the practical payoff. A traditional requirements document goes stale the moment the product changes, because nothing forces it to stay accurate. A BDD scenario fails the build when it stops matching the software.
The problem BDD attacks is ambiguity in language. A word like "account" can mean a line of credit to one person and a registration record to another, and both sides can use it for weeks before noticing they disagreed. Concrete examples force that ambiguity into the open, because a scenario has to name specific inputs and specific outcomes.
BDD did not start as a testing methodology. It started as an attempt to teach TDD better, and the sequence of steps that produced it explains why the practice looks the way it does.
North's original formulation of the template is worth quoting exactly, because most later versions add ceremony it never had: "Given some initial context (the givens), When an event occurs, Then ensure some outcomes."
The framework he built to prove the idea is still maintained. Teams working in Java can read our guide to JBehave testing for how it maps scenarios to step definitions today.
A BDD feature starts from a user story that states who wants the behavior and why, then enumerates the scenarios that prove the story is delivered. North's original illustration used an ATM withdrawal, and the shape has not changed since.
Feature: Customer withdraws cash
As a customer,
I want to withdraw cash from an ATM,
so that I don't have to wait in line at the bank.
Scenario: Account is in credit
Given the account is in credit
And the card is valid
And the dispenser contains cash
When the customer requests cash
Then ensure the account is debited
And ensure cash is dispensed
And ensure the card is returned
Scenario: Account is overdrawn past the overdraft limit
Given the account is overdrawn
And the card is valid
When the customer requests cash
Then ensure a rejection message is displayed
And ensure cash is not dispensedTwo details in that example carry most of the value. The story names the benefit, so a reviewer can challenge whether the feature is worth building at all. And the scenarios cover the rejection path, not only the success path, because a specification that describes only what works is not a specification.
Note the use of "And" to chain multiple givens or multiple outcomes without repeating the keyword. Each scenario still has exactly one "When", which is the discipline that keeps a scenario about one behavior.
Most BDD implementations fail here rather than at the tooling stage. The syntax is easy to adopt and the discipline behind it is not, so teams end up with automated scripts wearing Gherkin costume.
The single decision that determines whether scenarios survive contact with a changing product is whether they are written declaratively or imperatively. Here is the same sign-in behavior written both ways.
Imperative: describes the interface
Scenario: User logs in
Given I open "https://example.org/login"
When I type "test1" into the field with id "username"
And I type "Hello123" into the field with id "password"
And I click the button with id "submit"
Then I see an element with class "dashboard-header"That scenario breaks when the id of a field changes, and it tells a business reader nothing. It also cannot be reviewed for correctness, because nowhere does it state what the customer was supposed to achieve.
Declarative: describes the behavior
Scenario: Registered customer signs in successfully
Given a registered customer with valid credentials
When the customer signs in
Then the customer lands on their account dashboardThe selectors and the typing still exist, but they live in the step definition where they belong. When the login form is redesigned, one step definition changes and every scenario that signs a customer in keeps passing.
Teams rarely choose imperative steps deliberately. In the QA discussions on r/softwaretesting, a recurring account is a team that split one sign-in into separate steps for entering the username, entering the password, and clicking the button, specifically so business analysts could follow what the test did.
The instinct is right and the result is backwards. Readability was pursued at the level of the interface, which changes most often, instead of at the level of the behavior, which stays stable. If a business reader cannot follow "the customer signs in", the fix is a better-named step, not three smaller ones.
When the same behavior needs verifying against several data sets, copying the scenario is the wrong answer. A Scenario Outline states the behavior once and binds it to an Examples table.
Scenario Outline: Sign-in is rejected for invalid credentials
Given a registered customer
When the customer signs in with "<username>" and "<password>"
Then sign-in is rejected with the message "<message>"
Examples:
| username | password | message |
| test1 | wrongpass | Invalid username or password |
| unknown | Hello123 | Invalid username or password |
| | Hello123 | Username is required |Adding an edge case is now a new row rather than a new block of near-identical text. This is also where a specification earns its keep as documentation, because the table shows a reader every rejection rule in one view.
A scenario is only a specification until the step definitions drive real software. To confirm the Given-When-Then mapping end to end, we ran a scenario against the TestMu AI Selenium Playground Simple Form Demo on Chrome and Windows 11, with each step printing the value it observed.
Playwright Adapter: Connected successfully!
GIVEN page title : Selenium Grid Online | Run Selenium Test On Cloud
WHEN submitted message: BDD scenario verified on TestMu AI cloud
THEN displayed message: BDD scenario verified on TestMu AI cloud
RESULT : PASSED
DURATION: 20.1sThe run completed in 20.1 seconds on build 100399505. The point of printing the observed value on the Then step is that a green scenario then proves the assertion compared something real, which is the most common gap between a passing suite and a trustworthy one.
Note: Write scenarios in plain English and let TestMu AI's KaneAI turn them into running tests across 3,000+ browser and OS combinations. Try TestMu AI for free!
BDD grew out of TDD, so the two share a rhythm: describe the intent, watch it fail, implement, watch it pass. They differ in audience and in scope, and our detailed BDD vs TDD comparison works through the trade-offs in more depth.
| Aspect | Behavior-Driven Development | Test-Driven Development |
|---|---|---|
| Focus | How the system behaves from the user's point of view | Whether a unit of code does what the developer intended |
| Participants | Business representatives, developers, and testers together | Developers |
| Notation | Plain language scenarios, commonly Gherkin | The production programming language |
| Scope | End-to-end behavior spanning several units | A single class or function in isolation |
| Written when | Before implementation, during story refinement | Before implementation, during coding |
| Primary output | Shared understanding plus executable acceptance criteria | A regression-safe design and fast feedback on correctness |
The two are complementary rather than competing. A common arrangement is to drive the feature with a BDD scenario at the boundary and use TDD inside it for the units that implement the behavior.
One caution comes from the Agile Alliance, which observes that BDD requires familiarity with a greater range of concepts than TDD does, and that recommending BDD to a novice programmer without prior exposure to TDD concepts is difficult. Teams that have never practiced test-first development usually get more from learning TDD first.
BDD runs in three stages, and they happen in order for a reason: automating a scenario nobody discussed simply automates the misunderstanding.

A cross-functional group works through a story with concrete examples until everyone describes the behavior the same way. The output is not a document; it is the shared understanding, plus a list of the questions the conversation exposed.
Discovery is also where scope gets cut. Examples make it obvious when a rule serves an edge case nobody will hit, and cutting it costs a conversation rather than a sprint.
The agreed examples are written as structured scenarios, usually in Gherkin, while the conversation is still fresh. Our guide to writing Gherkin tests covers the keyword grammar in detail.
Formulation is a review gate, not transcription. Turning a verbal example into a precise scenario routinely reveals that the group agreed on wording but not on behavior.
Each step is bound to code that exercises the application, and the scenarios join the pipeline so every change is checked against the agreed behavior. Scenarios that were readable in formulation stay readable here only if the step definitions absorb the technical detail.
The Three Amigos is the practice of having three perspectives present when a story is refined. The roles matter less than the fact that three different failure modes of a requirement get caught at once.
Scenarios written by one role alone lose the benefit entirely. A tester writing scenarios after implementation is doing test design, which is useful, but it is not BDD and it will not prevent the feature from being built wrong.
Reviewing scenarios against acceptance criteria is where BDD meets ordinary test case practice, and the two should agree.
A BDD framework does one job: parse scenario files and map each step to executable code. It does not drive the browser or call the API, which is why the choice usually follows your team's language rather than a feature comparison.
| Framework | Primary language | Notes |
|---|---|---|
| Cucumber | Java, JavaScript, Ruby and others | The most widely used Gherkin runner, with the largest ecosystem of step libraries and reporters |
| SpecFlow | .NET | Keeps feature files separate from step definitions, which suits teams that maintain a large C# suite |
| Behave | Python | Plain Gherkin with Python step definitions and a light footprint |
| JBehave | Java | The original framework North wrote in 2003, built around verifying behavior rather than running tests |
| Behat | PHP | Context-aware step definitions that encourage reuse across suites |
The framework is not the hard part of BDD, and the Agile Alliance is explicit that the practice requires no particular tools or programming languages. Choose on language fit and on how well the runner reports failures, then spend the saved effort on scenario quality.
Language-specific walkthroughs are available for BDD testing with Python Behave and for Selenium testing with Gherkin.
The expensive step in BDD is formulation to automation: someone still has to write and maintain the step definitions that turn agreed sentences into working code. KaneAI from TestMu AI targets that step by generating executable tests directly from natural-language intent, and it can take a PRD, a Jira ticket, or a recorded session as the input rather than a blank test file.
Two of its behaviors matter for BDD specifically. Smart element detection resolves targets by intent instead of binding to a brittle selector, and reusable test modules let a common flow such as sign-in be authored once and composed into many tests, so one fix propagates everywhere the module is used.
Generated tests export to Selenium, Playwright, Cypress, and Appium, so a team keeps its existing suite as the system of record. The KaneAI documentation covers the authoring workflow. This reduces authoring and maintenance effort rather than eliminating it, and a human still reviews the generated plan before it runs.
BDD adoption fails more often on process than on tooling, because the practice asks roles that currently work in sequence to work at the same time. Before starting, confirm three things are in place.
A rollout that works:
One sequencing lesson from the testing communities is worth taking literally. The adoption accounts that describe a lasting result lead with the shared Given-When-Then vocabulary and deliberately avoid mentioning automation at first, because framing BDD as an automation project starts the argument about tooling before anyone has agreed on the behavior.
Consistency in acceptance criteria arrives first, and the runner and the pipeline follow once product owners, developers, and testers already write the same sentences. Reversing that order is what produces the feature files nobody outside QA reads.
Teams preparing for interviews or onboarding can use our BDD interview questions to check understanding of these fundamentals.
BDD has real costs, and they are worth stating plainly because most of the failure modes are predictable.

The sharpest version of this critique comes from practitioners rather than from methodology writing. In r/QualityAssurance, a recurring objection to Cucumber is that a plain-language step gives a non-technical reader no way to confirm the code behind it checks what the sentence claims, so the readability can be an illusion maintained at real cost.
The companion complaint across the same testing communities is blunter: when nobody outside QA reads or owns the scenarios, the feature files are ceremony, and the team is paying for a collaboration tool it never uses collaboratively. Both objections describe BDD adopted as a test-writing format rather than as a way of agreeing requirements, which is the failure this article's ordering of discovery before automation is meant to prevent.
None of these argue against BDD, but they do argue against adopting it for the tooling. If a team wants readable automated tests and not shared requirements, a well-structured test suite is cheaper.
Given-When-Then is itself one of the core test design patterns, so the practices below land better when the rest of your suite follows the same discipline.

Start with one story in your next refinement session. Get a business representative, a developer, and a tester to write its scenarios together in Given-When-Then, keep every step declarative, and note which questions the conversation exposed that the ticket had not.
That single session tells you whether BDD will pay off for your team, because the questions it surfaces are the rework it would have prevented. If they are numerous, the practice is worth the process cost; if the story was already unambiguous, your bottleneck is somewhere else.
Once the scenarios exist, run them where your users are. TestMu AI executes Cucumber, SpecFlow, and Behave suites in parallel across 3,000+ browser and OS combinations and 10,000+ real devices, and teams that would rather describe behavior than maintain step definitions can author the same flows in plain English with KaneAI.
Author
Sanjay Singh is a Senior Product Manager at TestMu AI (formerly LambdaTest), where he drives product strategy and go-to-market for the agentic AI quality engineering platform across web, mobile, and enterprise testing. He brings over seven years of experience across B2B SaaS, AI/ML, and FinTech. Earlier he was a Product Manager at ElectrifAi, where he led the development of SpendAI and a 14-member team and lifted customer acquisition by 20%, and at Inogic, where he grew annual revenue 30% year over year and recurring revenue 40% through a pricing revamp. Sanjay holds an MBA from IIM Lucknow and an Integrated Dual Degree in Biochemical Engineering from IIT (BHU) Varanasi.
Reviewer
Himanshu Sheth is the Director of Marketing (Technical Content) at TestMu AI, with over 8 years of hands-on experience in Selenium, Cypress, and other test automation frameworks. He has authored more than 130 technical blogs for TestMu AI, covering software testing, automation strategy, and CI/CD. At TestMu AI, he leads the technical content efforts across blogs, YouTube, and social media, while closely collaborating with contributors to enhance content quality and product feedback loops. He has done his graduation with a B.E. in Computer Engineering from Mumbai University. Before TestMu AI, Himanshu led engineering teams in embedded software domains at companies like Samsung Research, Motorola, and NXP Semiconductors. He is a core member of DZone and has been a speaker at several unconferences focused on technical writing and software quality.
Did you find this page helpful?
More Related Blogs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance