World’s largest virtual agentic engineering & quality conference

WHENAUG 19-21
WHEREVirtual · Global
Register Now
Testing

What is BDD Testing? Best Practices and Writing Test Cases

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.

Author

Sanjay Singh

Author

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

  • BDD is a collaboration practice: business, development, and testing agree how a feature should behave in plain language before any code exists.
  • Given-When-Then: a BDD scenario states one context, one triggering event, and one observable outcome.
  • Three stages, in order: BDD runs discovery, then formulation, then automation. Skipping BDD discovery automates the misunderstanding.
  • Declarative steps: write BDD steps for what the user achieves, because click-by-click steps break on the first UI change.
  • One When per scenario: limit each BDD scenario to a single When, because a second one hides which behavior broke.
  • No special tools required: the Agile Alliance states BDD needs no particular tools or programming languages, so a whiteboard is enough to start.
  • Running at scale: TestMu AI's test automation cloud executes BDD suites across 3,000+ browser and OS combinations.

What is Behavior-Driven Development (BDD)?

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:

  • Scenarios describe observable behavior from the user's point of view, not the internal implementation that produces it.
  • Scenarios are written before implementation, by several roles together, so ambiguity surfaces while it is still cheap to resolve.
  • The same artifact serves three purposes at once: it is the requirement, the documentation, and the automated test, so the three cannot drift apart.

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.

Why Teams Use Behavior-Driven Development

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.

  • Misunderstandings surface while the team writes scenarios, when the feature is still cheap to change.
  • Non-technical stakeholders can read and correct the specification themselves, which removes a translation step.
  • The Agile Alliance's "Five Whys" tactic ties each story to a business outcome, so features nobody can justify get descoped early.
  • Documentation stays current as a side effect of running the suite, because a scenario that no longer matches the system fails the build.

Origin of Behavior-Driven Development

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.

  • A colleague of North's, Chris Stevenson, wrote a utility called agiledox that printed JUnit method names as plain sentences. Developers noticed the output doubled as documentation and began naming test methods so they read as real sentences.
  • North adopted the convention of starting each method name with "should", which constrains a test to describing one behavior of the current class and answers the question of how much to test in one go.
  • At the end of 2003 he wrote JBehave, a JUnit replacement that removed the vocabulary of testing entirely and replaced it with a vocabulary of verifying behavior.
  • In late 2004, business analyst Chris Matts observed that this behavior-based vocabulary was really analysis. The two applied the same thinking to requirements, which produced the Given-When-Then scenario template.

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.

Behavior-Driven Development Example

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 dispensed

Two 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.

How to Write BDD Test Cases

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 dashboard

The 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.

Rules That Keep Scenarios Readable

  • Name the scenario after the outcome it proves, not the action it performs. "Sign-in is rejected after five failed attempts" tells a reader what broke when it fails; "Test login 3" does not.
  • Allow exactly one "When" per scenario. A second "When" means two behaviors are being verified together, and a failure will not say which one broke.
  • Keep incidental setup out of the Given steps. If a scenario about checkout begins by registering an account, push that into a background step or a fixture so the scenario stays about checkout.
  • Write in the third person and in the business vocabulary. "The customer" reads as specification; "I click" reads as a script transcript.
  • Avoid asserting on incidental detail such as exact pixel positions or generated ids. Assert on what a person would check to decide the behavior worked.

Data-Driven Cases With Scenario Outline

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.

Running a Scenario Against a Real Browser

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.1s

The 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

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 vs TDD: Key Differences

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.

AspectBehavior-Driven DevelopmentTest-Driven Development
FocusHow the system behaves from the user's point of viewWhether a unit of code does what the developer intended
ParticipantsBusiness representatives, developers, and testers togetherDevelopers
NotationPlain language scenarios, commonly GherkinThe production programming language
ScopeEnd-to-end behavior spanning several unitsA single class or function in isolation
Written whenBefore implementation, during story refinementBefore implementation, during coding
Primary outputShared understanding plus executable acceptance criteriaA 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.

The BDD Testing Process

BDD runs in three stages, and they happen in order for a reason: automating a scenario nobody discussed simply automates the misunderstanding.

The three stages of Behavior-Driven Development: discovery, formulation, and automation

Discovery

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.

Formulation

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.

Automation

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 in BDD

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.

  • The business representative, usually a product owner or business analyst, supplies the intent and the acceptance criteria, and can say whether an edge case is worth handling at all.
  • The developer surfaces technical constraints early, and flags where a requirement as worded would be disproportionately expensive to build.
  • The tester probes the paths the other two skip: invalid input, concurrency, permissions, and what should happen when a dependency is unavailable.

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.

BDD Testing Tools and Frameworks

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.

FrameworkPrimary languageNotes
CucumberJava, JavaScript, Ruby and othersThe most widely used Gherkin runner, with the largest ecosystem of step libraries and reporters
SpecFlow.NETKeeps feature files separate from step definitions, which suits teams that maintain a large C# suite
BehavePythonPlain Gherkin with Python step definitions and a light footprint
JBehaveJavaThe original framework North wrote in 2003, built around verifying behavior rather than running tests
BehatPHPContext-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.

Where AI Authoring Fits

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.

Automate web and mobile tests with KaneAI by TestMu AI

How to Implement BDD Testing

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.

  • Business, development, and testing can get in a room together during refinement. Without that, scenarios become a document one person writes and the practice collapses into a syntax choice.
  • The team shares a vocabulary for the domain, or is willing to build one. Disagreement about what "order", "account", or "active user" means is the problem BDD solves and also the thing that stalls it.
  • Acceptance criteria can be stated in measurable terms. "The page should be fast" cannot become a scenario; "search results return within two seconds for a catalogue of 10,000 products" can.

A rollout that works:

  • Pick one team and one well-bounded product area. A pilot that fails in a small scope is a lesson; a company-wide rollout that fails discredits the practice for years.
  • Run discovery on a handful of stories before automating anything, so the team experiences the conversation as the deliverable rather than the scenarios.
  • Automate only the scenarios that survived discovery unchanged, which keeps the first suite small enough to maintain while step-definition conventions settle.
  • Wire the suite into the pipeline early, since scenarios that run only on demand stop reflecting the product within weeks.
  • Measure rework rather than scenario count. If defects traced to misunderstood requirements are not falling, the conversations are not working and more scenarios will not fix it.

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.

Challenges of BDD Testing

BDD has real costs, and they are worth stating plainly because most of the failure modes are predictable.

Common challenges teams face when adopting Behavior-Driven Development
  • The conversation is the expensive part. Three people refining a story together costs more calendar time than one analyst writing a ticket, and that cost is visible while the savings in avoided rework are not.
  • Scenario quality degrades quietly. Imperative steps creep in one scenario at a time, and by the time the suite is unreadable, rewriting it competes with delivery work.
  • Step-definition sprawl follows scenario sprawl. Without conventions for reuse, teams end up with several near-identical steps that drift apart and produce inconsistent behavior.
  • The learning curve is steeper than it looks. The Agile Alliance notes BDD requires familiarity with a greater range of concepts than TDD, which is why teams new to test-first development often struggle.
  • Automation can be mistaken for the whole practice. A team can run thousands of Gherkin scenarios and still ship the wrong feature if nobody had the discovery conversation.

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.

BDD Testing Best Practices

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.

Best practices for writing and maintaining Behavior-Driven Development scenarios
  • Hold discovery before formulation, every time. The order is the practice; reversing it produces scenarios that document one person's assumptions.
  • Keep every scenario declarative, and treat an element id or a CSS class appearing in a feature file as a defect to fix rather than a style preference.
  • Promote repeated steps into shared definitions early, so a change to sign-in touches one file instead of forty scenarios.
  • Use Scenario Outline for data variation and reserve separate scenarios for genuinely different behavior. Copied scenarios that differ by one value are the main cause of unreadable feature files.
  • Delete scenarios that no longer describe the product instead of skipping them. A skipped scenario is a documentation lie that still costs maintenance.
  • Run the suite on the browsers and devices your users actually have, since a scenario that passes only on the developer's Chrome proves less than it appears to.
  • Track defects caused by misunderstood requirements as the health metric. Scenario count and pass rate can both rise while the practice quietly stops working.
Run tests up to 70% faster on the TestMu AI cloud grid

Conclusion

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

  • Linkedin

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

Reviewer

  • Linkedin

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.

Open in ChatGPT Icon

Open in ChatGPT

Open in Claude Icon

Open in Claude

Open in Perplexity Icon

Open in Perplexity

Open in Grok Icon

Open in Grok

Open in Gemini AI Icon

Open in Gemini AI

Copied to Clipboard!
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free
...
TestMu Conf 2026

World's largest virtual agentic engineering & quality conference

...

AUG 19-21, 2026

REGISTER NOW

BDD FAQs

Did you find this page helpful?

More Related Blogs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests