Gherkin feature files

Version 0.2.0 Updated Dec 08, 2025

Gherkin files describe behaviour in a structured, plain‑text format that can be read by both technical and non‑technical stakeholders. Each .feature file begins with a Feature declaration that provides a high‑level description of the functionality. A feature contains one or more Scenario sections, each of which documents a single example of system behaviour. Inside a scenario, the behaviour is expressed through a sequence of steps starting with Given (context), followed by When (action) and ending with Then (expected outcome). Secondary keywords And and But may chain additional steps of the same type for readability.

Scenarios follow the simple Given‑When‑Then pattern. Support for Scenario Outline is available, enabling a single scenario to run with multiple sets of data from an Examples table. A Background section defines steps that run before each Scenario in a feature file, enabling shared setup across scenarios. Advanced constructs such as data tables and Docstrings provide structured or free‑form arguments to steps.

Example feature file

Feature: Shopping basket

  Scenario: Add item to basket
    Given an empty basket
    When the user adds a pumpkin
    Then the basket contains one pumpkin

The feature file lives within the crate (commonly under tests/features/). The path to this file will be referenced by the #[scenario] macro in the test code.

Internationalised scenarios

rstest-bdd reads the optional # language: <code> directive that appears at the top of a feature file. When a locale is specified, the parser uses that language's keyword catalogue, enabling teams to collaborate in their native language. The examples/japanese-ledger crate demonstrates the end-to-end workflow for Japanese:

# language: ja
フィーチャ: 家計簿の残高を管理する
  シナリオ: 収入を記録する
    前提 残高は0である
    もし 残高に5を加える
    ならば 残高は5である

Step definitions use the same Unicode phrases:

use japanese_ledger::HouseholdLedger;
use rstest_bdd_macros::{given, when, then};

#[given("残高は{start:i32}である")]
fn starting_balance(ledger: &HouseholdLedger, start: i32) {
    ledger.set_balance(start);
}

Running cargo test -p japanese-ledger executes both Japanese scenarios. The full source lives under examples/japanese-ledger/ for teams that want to copy the structure into their projects.