Back to all posts

What Is Given-When-Then? Writing BDD Test Cases in Practice

Given-When-Then is a fixed sentence structure from BDD that splits test cases into precondition, action, and outcome — keeping cases consistent no matter who writes them. This guide covers the format, practical tips, and common anti-patterns.

Bob Chen·

"Test that login fails with the wrong password" is a fine test case title on its own, but once a team grows and case counts climb, free-form sentences quickly drift — some people write overly detailed steps, others write vague ones. Given-When-Then is a fixed sentence structure from behavior-driven development (BDD) that keeps test cases consistent no matter who writes them, so PMs, engineers, and QA can all read the same thing the same way.

What is Given-When-Then?

Given-When-Then splits a test case into three parts:

  • Given: the state the system or user is in before the action happens.
  • When: the actual action the user takes.
  • Then: what the system should do as a result.

The format comes from Behavior-Driven Development (BDD), originally used in tools like Cucumber and SpecFlow to write executable specifications. But even if your team doesn't automate anything, using this structure for manual test cases alone makes them more consistent and easier to reuse.

Breaking down the three parts

PartPurposeCommon mistake
GivenEstablishes the precondition so the case is reproducibleOmitting the precondition, leaving the reader unsure what state to start from
WhenA single, unambiguous actionCramming two or three actions into one When, so a failure can't be pinned to a specific step
ThenA verifiable, observable outcomeWriting something unverifiable like "should work correctly"

Side by side: plain writing vs. Given-When-Then

Plain writing: "Test the login failure case." — the reader has no idea what the precondition is, what to enter, or what to expect.

Given-When-Then:

  • Given the account is registered and active
  • When the user enters the correct account with the wrong password and submits
  • Then the system shows "invalid credentials" and does not create a session

The difference: anyone picking up the second version can reproduce it exactly, and it's immediately obvious what the case is actually verifying.

4 practical tips for writing them

  1. One When, one action: if the action needs "and then" to connect two steps, that's usually a sign it should be two separate cases.
  2. Give only what's relevant: don't describe the entire system state — only the parts that actually affect this verification.
  3. Make Then concretely verifiable: "shows an error message" beats "fails," and "does not create a session" beats "security works correctly."
  4. Use consistent vocabulary: agree as a team on terms like "active," "disabled," "verified" — don't let everyone invent their own wording.

Common anti-patterns

  • Hard-coding UI details into When: e.g. "click the third blue button in the top-left corner" — a UI redesign breaks the case immediately. "Submit the login form" ages much better.
  • Stuffing multiple unrelated checks into Then: e.g. verifying both "shows an error message" and "writes an audit log" in one Then — split these into two independent cases that can pass or fail on their own.
  • Writing Given as another test case's steps: a precondition should describe "an existing state," not a hidden checklist like "first run steps A, B, C."

How does this connect to test case management?

Once the format is consistent, cases become much easier to manage structurally — the same Given state can be reused across multiple When/Then pairs, and when a requirement changes, it's easier to ask "does this Given still hold true?" If you don't have a central place to manage these cases yet, see "What Is Test Case Management?"; if you're comparing tools, "8 Test Management Tools Compared in 2026" covers the common options. OpenTestX also relies on clearly written Given/Then statements to accurately judge which cases might no longer match a changed requirement.

FAQ

Is Given-When-Then only for automated tests?

No. The format originated to serve automation (BDD tools parse it into executable scripts), but it works just as well for purely manual test cases — the benefit is consistency, without needing to hook into any automation framework at all.

Does every case need to be strictly written in three parts?

In principle, yes — but exploratory testing or very trivial checks don't need to be forced into the format. Given-When-Then is most valuable for cases that get re-run repeatedly, handed off to others, or formally added to your test assets.

Can one case have multiple Whens?

Generally not recommended. Multiple Whens usually mean the case is testing an entire flow rather than a single behavior, which makes failures hard to pinpoint. If you genuinely need to verify a full flow, split it into multiple independent cases, or write a separate "end-to-end flow" case and label its purpose clearly.


Given-When-Then isn't extra bureaucracy — it's what makes a test case itself verifiable, reproducible, and handoff-ready. Once the format is consistent, your test assets actually become assets, instead of a pile of sentences everyone phrases their own way.

Talk to the team

Curious how this looks inside your team?

Book a short consult and we will walk through how OpenTestX maps to your current QA system.

Book a consultation →