A BDD testing framework integrating Gherkin-style tests with ZIO’s effect system
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).
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.
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
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 define the actions and assertions in a scenario. They use the following keywords:
Given conditions).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!"
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!"
"..." for strings.string, int).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! |
List[User] to step definitions.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! |
Examples table for each row.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!"
zio-bdd (e.g., run only @smoke tests).Comments start with # and are ignored during execution.
# This is a comment
Feature: User Greeting
Scenario Outline for data-driven tests.