How do I  

How to Write Acceptance Criteria Using Given-When-Then

๐Ÿ”น Introduction

When building software in Agile development, clear communication between developers, testers, and business teams is very important. One of the best ways to ensure clarity is by writing acceptance criteria. These criteria act as a checklist to confirm that a user story is complete and working as expected.

๐Ÿค” What Are Acceptance Criteria?

Acceptance criteria are conditions that a software product must meet to be accepted by the user, customer, or business team. They describe the expected behavior of the system and help ensure that the requirements are met.

For example:

  • A login featureโ€™s acceptance criteria could be: โ€œThe system should allow users to log in with valid credentials and show an error message for invalid ones.โ€

Acceptance criteria remove confusion and ensure that everyone understands the definition of โ€œdone.โ€

๐Ÿ“Œ Why Use Given-When-Then Format?

The Given-When-Then format is part of Behavior-Driven Development (BDD). It helps describe scenarios in a structured way:

  • Given โ€“ the starting context or precondition.

  • When โ€“ the action taken by the user or system.

  • Then โ€“ the expected outcome.

This format is useful because:

  • โœ… It avoids ambiguity.

  • โœ… Itโ€™s easy to read for both technical and non-technical people.

  • โœ… It works well for automation testing.

๐Ÿ“ Structure of Given-When-Then

Each acceptance criteria scenario should follow this simple structure:

Given [some context]
When [an action is performed]
Then [an expected result should occur]

You can also use And to add more steps if needed:

Given the user is on the login page
When the user enters valid credentials
And clicks the login button
Then the user should be redirected to the dashboard

๐Ÿ“– Example 1: Login Feature

User Story: As a registered user, I want to log in so that I can access my dashboard.

Acceptance Criteria (Given-When-Then format):

Scenario: Successful login
  Given the user is on the login page
  When the user enters valid credentials
  Then the system should log them in
  And redirect to the dashboard

Scenario: Unsuccessful login
  Given the user is on the login page
  When the user enters invalid credentials
  Then the system should display an error message
  And stay on the login page

๐Ÿ“– Example 2: Shopping Cart

User Story: As a customer, I want to add items to my cart so that I can purchase them later.

Acceptance Criteria:

Scenario: Adding an item to the cart
  Given the customer is on the product page
  When they click โ€œAdd to Cartโ€
  Then the item should appear in their cart
  And the cart count should increase by one

Scenario: Removing an item from the cart
  Given the customer has an item in the cart
  When they click โ€œRemoveโ€
  Then the item should disappear from the cart
  And the cart count should decrease

๐Ÿ” Tips for Writing Good Acceptance Criteria

  • Keep it simple โ€“ Use plain language.

  • Be specific โ€“ Avoid vague terms like โ€œworks correctlyโ€. Instead, describe expected outcomes.

  • Cover edge cases โ€“ Write scenarios for both valid and invalid inputs.

  • Collaborate โ€“ Involve testers, developers, and product owners while writing.

  • Use multiple scenarios โ€“ If a feature has many conditions, write separate scenarios.

๐Ÿ“Š Benefits of Using Given-When-Then

  • โœ… Ensures clear communication across teams.

  • โœ… Helps testers design better test cases.

  • โœ… Provides a strong foundation for automated testing.

  • โœ… Improves software quality by catching issues early.

  • โœ… Enhances customer satisfaction by meeting requirements.

๐Ÿ“ Summary

Acceptance criteria define when a user story is complete and working as expected. Using the Given-When-Then format makes criteria clear, testable, and easy to understand. By structuring scenarios with preconditions (Given), actions (When), and outcomes (Then), Agile teams ensure that requirements are properly met. Whether itโ€™s logging in, shopping, or complex workflows, GWT brings clarity and improves software quality, making it a powerful tool for Agile development and software testing.