What is Given/When/Then Format?
Given/When/Then is a structured format for writing acceptance criteria and test scenarios that describes a precondition (Given), a user action (When), and an expected outcome (Then).
Given/When/Then Format: In Depth
Given/When/Then — sometimes called Gherkin syntax or BDD (Behavior-Driven Development) format — is a template for writing acceptance criteria and test cases in plain English that is both human-readable and machine-parseable. The three clauses work together: "Given" establishes the context or precondition before an action occurs; "When" describes the specific action or event; "Then" specifies the observable outcome that should result.
A concrete example helps illustrate the format: "Given a logged-in user on the checkout page, When they enter a valid credit card and click 'Pay', Then they should see an order confirmation page and receive a confirmation email." This single criterion captures the who, the action, and the measurable result in a form that a developer, tester, and non-technical stakeholder can all understand and agree on.
The format's power lies in its precision without technical jargon. Because each criterion has a defined starting state, a specific trigger, and a verifiable outcome, there is little room for ambiguous interpretation. Developers know exactly what behavior to implement; testers know exactly what to verify; product owners can read criteria without needing technical knowledge. Tools like Cucumber can even execute Given/When/Then steps directly as automated tests, creating a living specification that proves the system behaves as described.
Codepylot's AI story rewrite feature automatically generates acceptance criteria in Given/When/Then format for every story it produces. When an AI coding agent picks up a story, it uses these structured criteria as a precise specification — each "Then" clause is a test it knows it must satisfy. This tight loop between human-readable criteria and automated implementation is one of the key reasons AI agents produce higher-quality output when working with well-structured stories compared to loose, informal descriptions.
Related Terms
User Story
A user story is a short, plain-language description of a software feature written from the end user's perspective, typically following the format: 'As a [user], I want [goal] so that [benefit].'
Acceptance Criteria
Acceptance criteria are the specific conditions a user story must satisfy to be considered complete and accepted by the product owner or stakeholder.
Sprint Planning
Sprint planning is an agile ceremony where a team selects user stories from the backlog to work on during an upcoming sprint, estimates effort, and commits to a sprint goal.
AI Coding Agent
An AI coding agent is an autonomous software system that can read a feature description, write code to implement it, create git branches, run tests, and open pull requests with minimal human intervention.
Definition of Done
Definition of done (DoD) is a team-agreed checklist of criteria that every user story must meet before it can be considered complete and accepted, ensuring consistent quality across all delivered work.
Related Resources
Put Given/When/Then Format into Practice with Codepylot
Codepylot turns rough ideas into structured user stories and ships them with autonomous AI coding agents. Free plan includes 3 projects and AI story generation.
Get Started FreeFrequently Asked Questions
What does Given/When/Then stand for in BDD?
In Behavior-Driven Development (BDD), 'Given' describes the initial context or state of the system before an action. 'When' describes the action or event that triggers a behavior. 'Then' describes the expected observable outcome. Together, they form a complete, unambiguous test scenario that bridges communication between developers, testers, and stakeholders.
Can I have multiple 'And' clauses in Given/When/Then?
Yes. 'And' extends any of the three clauses with additional conditions. For example: 'Given a logged-in admin user, And the user has billing enabled, When they navigate to the billing page, Then they should see their current plan, And they should see an upgrade button.' Using 'And' avoids repeating the clause keyword while keeping scenarios readable.
Is Given/When/Then only for BDD or can I use it for regular acceptance criteria?
Given/When/Then is widely used for plain acceptance criteria regardless of whether you follow a formal BDD process or use BDD test frameworks like Cucumber or SpecFlow. The format's clarity makes it valuable for any team that wants unambiguous, testable acceptance criteria. Codepylot generates Given/When/Then criteria for all AI-rewritten stories regardless of your testing setup.