Understanding the structure of Gherkin

Focus on the "What" - not the "How"

Gherkin organizes acceptance criteria into a clear, predictable structure that describes the behavior of a system. It uses specific keywords to frame scenarios:

  • Feature: A high-level description of what the system is expected to do.
  • Scenario: A single example or use case that illustrates the behavior.
  • Given: Sets the initial state or context before an action occurs.
  • When: Describes the action or event that triggers the behavior.
  • Then: Specifies the expected outcome or result of the action.
  • Additional steps can be added using And or But to extend the context, actions, or outcomes.

This structure keeps acceptance criteria organized and consistent, making it easier for everyone to understand the requirements.

 

Steps to Writing Gherkin-Style Acceptance Criteria

1. Define the Feature

Start by describing the feature in simple terms, focusing on its purpose and the value it delivers. A feature should encapsulate what the functionality aims to achieve and why it matters to the user or business.

 

2. Break It into Scenarios

Each feature can have multiple scenarios that outline specific examples of how the system behaves. Think about both typical and edge cases, ensuring you cover a range of possibilities.

 

3. Use the Given-When-Then Framework

  • Given establishes the initial conditions or state.
  • When specifies the event or action performed by the user or system.
  • Then explains the desired outcome, focusing on what happens next.

This framework ensures clarity by separating context, actions, and results into distinct steps.

 

4. Write from the User’s Perspective

Focus on the user's experience and the outcomes they expect, rather than technical implementation details. This ensures that the acceptance criteria remain user-centric and business-relevant.

 

5. Keep It Testable

Every scenario should describe something that can be tested. Avoid ambiguous terms like "appropriate" or "reasonable" and be specific about the expected behavior.

 

6. Collaborate on Scenarios

Writing Gherkin scenarios should be a collaborative effort involving developers, testers, and business stakeholders. This ensures that the acceptance criteria reflect the needs of all parties and reduce misunderstandings.

©Copyright. All rights reserved.

We need your consent to load the translations

We use a third-party service to translate the website content that may collect data about your activity. Please review the details in the privacy policy and accept the service to view the translations.