zio-bdd

A BDD testing framework integrating Gherkin-style tests with ZIO’s effect system

View the Project on GitHub EtaCassiopeia/zio-bdd

Gherkin Syntax Reference

This page provides a comprehensive reference for writing feature files in zio-bdd using Gherkin syntax. Gherkin is a human-readable, domain-specific language that describes application behavior in a structured format, making it ideal for Behavior-Driven Development (BDD).

Overview

Gherkin files (.feature) consist of keywords like Feature, Scenario, Given, When, Then, And, and But. These keywords help define the behavior of your application in a way that’s understandable to both technical and non-technical stakeholders.

Structure of a Feature File

Feature

The Feature keyword defines the high-level functionality or behavior being described. It’s followed by a name and an optional description.

Feature: User Greeting
  As a system
  I want to greet users by name
  So that they feel welcomed

Scenario

A Scenario outlines a specific example or test case for the feature. It’s a sequence of steps that describe a single path of behavior.

Scenario: Greet a user
  Given a user named "Alice"
  When the user is greeted
  Then the greeting should be "Hello, Alice!"

Steps

Steps define the actions and assertions in a scenario. They use the following keywords:

Example with multiple steps:

Scenario: Greet a user with a title
  Given a user named "Alice"
  And the user has the title "Dr."
  When the user is greeted
  Then the greeting should be "Hello, Dr. Alice!"

Parameterization

Steps can include parameters (e.g., strings, numbers) enclosed in quotes. These are extracted and passed to step definitions in zio-bdd.

Given a user named "Alice"
Then the greeting should be "Hello, Alice!"

Data Tables

Data tables provide structured input or expected output for steps, written with | delimiters.

Scenario: Greet multiple users
  Given the following users:
    | name  | title |
    | Alice | Dr.   |
    | Bob   | Mr.   |
  When the users are greeted
  Then the greetings should be:
    | greeting         |
    | Hello, Dr. Alice!|
    | Hello, Mr. Bob!  |

Scenario Outlines

A Scenario Outline allows running the same scenario with multiple examples, using placeholders (<placeholder>) and an Examples table.

Scenario Outline: Greet a user with different names
  Given a user named "<name>"
  When the user is greeted
  Then the greeting should be "<greeting>"
  Examples:
    | name  | greeting      |
    | Alice | Hello, Alice! |
    | Bob   | Hello, Bob!   |

Tags

Tags (e.g., @smoke, @wip) filter or categorize scenarios. Add them above Feature or Scenario.

@smoke
Feature: User Greeting

@wip
Scenario: Greet a user
  Given a user named "Alice"
  When the user is greeted
  Then the greeting should be "Hello, Alice!"

Comments

Comments start with # and are ignored during execution.

# This is a comment
Feature: User Greeting

Best Practices

Next Steps