# BDD testing with Gherkin and Cucumber

> Run a Gherkin Scenario Outline with Cucumber.js. Compare three delivery-rule examples, executable step definitions and actual passing and failing results.

Source: https://cueapril.com/testing/gherkin-testing
Updated: 2026-10-15
Index: https://cueapril.com/llms.txt

## What is BDD testing?

Behaviour-driven development (BDD) helps a team agree how software should behave using concrete examples. Gherkin records examples as Given, When, Then scenarios. A runner such as Cucumber matches each step to code and reports which scenarios passed, failed or stayed incomplete.

Gherkin scenarios give a team a shared way to describe expected behaviour. With Cue April, execute supported Cucumber scenarios from your approved repository scope and see which examples passed, failed or still need attention.

## Describe one rule with concrete examples.

Our fictional delivery rule charges 500p below £50 and nothing from £50. A Scenario Outline expresses the same behaviour at 4999p, 5000p and 5001p. Cucumber expands each Examples row into its own scenario; the header names fill the angle-bracket placeholders. This keeps the exact threshold visible to developers and the person approving the rule.

features/delivery.feature

```gherkin
Feature: Delivery charges
  Delivery costs 500p below £50 and is free from £50.

  Scenario Outline: The basket determines the delivery charge
    Given a basket worth <basket> pence
    When I calculate its delivery charge
    Then the charge is <charge> pence

    Examples:
      | basket | charge |
      | 4999   | 500    |
      | 5000   | 0      |
      | 5001   | 0      |
```

## Connect the Gherkin to assertions that run.

A feature file needs executable step definitions. Here, Given stores the basket value, When calls the selected function and Then compares the actual charge with the expected charge. Normal functions give each scenario access to its own Cucumber World. The world parameter selects the deliberately buggy function for the negative demonstration.

features/steps.mjs

```javascript
import assert from 'node:assert/strict';
import { Given, When, Then } from '@cucumber/cucumber';
import { deliveryPence } from '../src/delivery.mjs';
import { deliveryPence as buggyDeliveryPence } from '../src/delivery-buggy.mjs';

Given('a basket worth {int} pence', function (basketPence) {
  this.basketPence = basketPence;
});
When('I calculate its delivery charge', function () {
  const calculate = this.parameters.buggy ? buggyDeliveryPence : deliveryPence;
  this.chargePence = calculate(this.basketPence);
});
Then('the charge is {int} pence', function (expectedPence) {
  assert.equal(this.chargePence, expectedPence);
});
```

The [Cucumber Gherkin reference](https://cucumber.io/docs/gherkin/reference/) explains Scenario Outlines, and [Cucumber.js step definitions](https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/step_definitions.md) document how steps connect to code.

## Run both versions and inspect the actual failure.

The downloaded package pins Cucumber.js 13.3.0. Against the deliberate > boundary defect, the 5000p scenario fails: actual delivery is 500p when the requirement says 0p. The 4999p and 5001p scenarios pass. With the corrected >= function, all three scenarios pass. These were local executions of an owned educational fixture.

Run with Node 24 from the downloaded example folder

```bash
npm ci --ignore-scripts
npm run test:gherkin:bug
# The buggy command intentionally exits 1.
npm run test:gherkin
```

Observed local Cucumber output

```text
Buggy: 3 scenarios (2 passed, 1 failed)
       9 steps (8 passed, 1 failed)
       AssertionError: 500 !== 0

Fixed: 3 scenarios (3 passed)
       9 steps (9 passed)
```

## Keep incomplete scenarios separate from passes.

An undefined step needs an implementation. An ambiguous step needs its matching rules fixed. A pending, skipped or blocked scenario has not established the required behaviour. Inspect the scenario result and native report, rather than treating the existence of a feature file as coverage. The archive preserves JSON reports for both local runs.

## Choose scenarios around a buying or access decision.

Use agreed examples for rules such as pricing, tenant boundaries or permissions. Include an exact boundary, a permitted action and an action that should be denied. Keep the scenario about behaviour that matters to a person; put selectors and implementation details in the step code. [Generated properties](/testing/property-based-testing) can explore a wider input domain after the concrete examples are clear.

## Run your supported scenarios within an approved plan.

Cue April can run supported installed Cucumber suites from your repository and retain scenario outcomes and native reports. Setup checks the step definitions, dependencies, environment, selected tags and qualified runner. Combine those results with [API checks](/testing/api-testing) or [browser testing](/testing/playwright-testing) for the same revision. [Discuss the scope of an evaluation](/demo).

## Reproduce the example

A fictional delivery rule with a deliberately seeded boundary defect. These examples were executed locally. They contain no customer data, AI calls or hosted Cue April execution.

Verified 2026-10-15 with Node 24.21.0, fast-check 4.10.2, Stryker 10.0.0 and Cucumber 13.3.0.

[Download runnable examples](https://cueapril.com/examples/testing-business-rules.zip)

[Read source and recorded results](https://cueapril.com/examples/testing-business-rules/index.html)

## Primary documentation

- [Cucumber: Gherkin reference and Scenario Outlines](https://cucumber.io/docs/gherkin/reference/)
- [Cucumber.js: executable step definitions](https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/step_definitions.md)

By Cue April. Updated 2026-10-15.

## Questions

### Will retries hide a failing scenario?

Native invocations disable Cucumber retries so earlier failures remain visible. Approved repeated invocations preserve each attempt, with mixed outcomes reported as incomplete.

### Does repeating a scenario independently confirm a defect?

Repeated invocations share a workspace and environment. Independent reproduction is a separate fresh-execution workflow with its own evidence requirements.

### What does Gherkin syntax look like?

A scenario reads like this: Given a basket worth £49, When the customer checks out, Then a delivery charge is added. Each Given, When or Then line is a step, and Cucumber matches every step to the code that performs it.

### Is Cucumber BDD or TDD?

Cucumber is a BDD tool: it runs scenarios that describe behaviour in business language. Test-driven development works at the code level, usually with unit tests written before the code. Many teams use both practices together.

### Is Gherkin testing the same as Cucumber testing?

Gherkin is the language the scenarios are written in, and Cucumber is one of the tools that runs them. So “Gherkin testing” and “Cucumber testing” usually describe the same practice from two different angles.

## Related

- [Playwright testing](https://cueapril.com/testing/playwright-testing): An AI testing agent runs your approved Playwright tests and keeps the results, source identity and gaps. Review accessibility scans alongside journeys.
- [API testing](https://cueapril.com/testing/api-testing): Automated API testing with approved assertions and schema campaigns. Inspect response checks, failed cases and the exact scope behind each result.
- [Agentic testing](https://cueapril.com/guides/agentic-software-testing): Agentic testing explained: approved intent, coordinated test methods, reproducible findings and evidence for a human release decision.
