Gherkin

Description
A structured, domain-specific language using Given-When-Then syntax to define behavioral specifications that are both human-readable and machine-actionable.
Status
Live
Last Updated
Tags
Testing, Specification, BDD, Syntax

Definition

Gherkin is a structured, domain-specific language using Given-When-Then syntax to define behavioral specifications in plain text. While Behavior-Driven Development provides the methodology, Gherkin provides the concrete syntax.

Gherkin’s effectiveness for LLM agents stems from its properties: human-readable without technical jargon, machine-parseable with predictable structure, and aligned between technical and non-technical stakeholders. Each keyword defines a phase of reasoning that prevents agents from conflating setup, action, and verification into an undifferentiated blob.

The Given-When-Then Structure

Gherkin scenarios follow a consistent three-part structure:

Feature: User Authentication
  As a registered user
  I want to log into the system
  So that I can access my personalized dashboard

  Scenario: Successful login with valid credentials
    Given a registered user with email "user@example.com"
    And the user has password "SecurePass123"
    When the user submits login credentials
    Then the user should be redirected to the dashboard
    And a session token should be created

Keyword Semantics

KeywordTraditional BDDAgentic Translation
GivenPreconditions or initial stateContext setting, memory retrieval, environment setup
WhenThe trigger event or user actionTask execution, tool invocation, decision step
ThenThe observable outcomeVerification criteria, alignment check, evidence-of-done
And/ButAdditional conditions within a stepLogical constraints, secondary validation parameters
FeatureHigh-level description of functionalityFunctional blueprint, overall agentic goal
BackgroundSteps common to all scenariosPre-test fixtures, global environment variables

ASDLC Usage

Gherkin isn’t just a testing syntax—it’s a semantic constraint language for agent behavior.

When an agent reads a Gherkin scenario:

  • Given tells it what to assume (context setup)
  • When tells it what action to take (execution scope)
  • Then tells it what success looks like (verification criteria)

This partitioning prevents “context bleed” where agents conflate setup, action, and verification.

In Specs: The Spec Contract section uses Gherkin scenarios:

## Contract

### Scenarios

#### Happy Path
Given a valid API key
When the user requests /api/notifications
Then the response returns within 100ms
And the payload contains the user's notifications

Applied in:

  • The Spec — Contract section uses Gherkin scenarios
  • Context Gates — Gherkin scenarios define gate verification criteria
  • Living Specs — Gherkin scenarios evolve with the feature

References

  1. Cucumber . Gherkin Reference . Accessed January 12, 2026.

    Canonical documentation for Gherkin syntax and semantics.

  2. Agile Alliance . Behavior Driven Development . Accessed January 12, 2026.

    Industry-standard glossary covering BDD and Gherkin terminology.