TDD vs BDD: Who Needs to Read the Test?
TDD starts from a failing test a developer writes, BDD from a scenario the team agrees on. See both run on one discount code and pick by who reads the test.
A shop wants a discount code. SAVE10 takes 10% off an order of $50 or more. One developer opens a test file and writes a failing assertion. Another team opens a plain-text file and writes “Given a cart worth $80.00.” Both are about to build the same function, and both will watch a test go red before it goes green.
TDD and BDD run the same loop with a different first artifact, so the working question is who needs to read the test. We took that discount code through both loops, in Jest and in Cucumber.js, and every output below comes from the run.
What you’ll learn
- What TDD and BDD share and the one thing they start from differently
- A discount code built test-first in Jest, with every red
- The same code driven by Gherkin scenarios in Cucumber.js, glue included
- How to pick, based on who needs to read the test
What Is the Difference Between TDD and BDD?
Test-driven development (TDD) starts from a failing test a developer writes in code. Behavior-driven development (BDD) starts from a scenario the team agrees on in plain language, then automates it. Both write the test before the code, and both run red, green, refactor.
TDD came first. Martin Fowler credits Kent Beck with developing it in the late 1990s as part of Extreme Programming, as three steps repeated: write a test for the next bit of functionality, write code until it passes, then refactor.
BDD grew out of coaching that loop. In Introducing BDD (2006), Dan North describes naming tests as sentences about behavior, until he started calling TDD “behaviour-driven development.” The same post records the shape his team settled on for scenarios: given some initial context, when an event occurs, then ensure some outcomes.
| Dimension | TDD | BDD |
|---|---|---|
| First artifact | A failing test, in code | A scenario, in plain language |
| Written by | The developer building the code | Product, QA and developers together |
| Read by | Developers | Anyone who can read the rules of the feature |
| Usual level | One function or class | One behavior a user or a business rule cares about |
| Extra layer | None | Step definitions that bind each sentence to code |
TDD writes the first test for a developer. BDD writes it for the whole team, then pays for a translation layer so the computer can read it too.
TDD on the Discount Code: Four Reds and a Refactor
The idea here is to let each failing test pull exactly one rule into the code. We ran both paths on Node 22.21.0 with Jest 30.5.2 and Cucumber.js 13.3.0, on Windows 11, so the file paths in Cucumber’s output use backslashes. Install Jest with npm install --save-dev jest. The first test goes in test/discount.test.js before src/discount.js exists:
const { applyDiscount } = require('../src/discount');
test('SAVE10 takes 10% off an $80 cart', () => {
expect(applyDiscount(80, 'SAVE10')).toEqual({ total: 72, message: 'SAVE10 applied' });
});
npx jest goes red for the most basic reason there is:
FAIL test/discount.test.js
● Test suite failed to run
Cannot find module '../src/discount' from 'test/discount.test.js'
This is the red you expect: the test exists and the code doesn’t. The smallest code that turns it green is a function that always takes 10% off. It is wrong, and the next test proves it. We ran the loop four times, adding one test each time:
| Test added | Red because | Green with |
|---|---|---|
| 10% off an $80 cart | No module yet | Always return 90% of the subtotal |
| $50 minimum spend | A $40 cart came back as 36 | An early return under $50 |
| Unknown code changes nothing | FREESHIP still took 10% off, 80 became 72 | Reject any code other than SAVE10 |
| Rounds to the cent | A $59.99 cart came back as 53.991 | Multiply by 90 and round before dividing by 100 |
The last red is the one worth having. Ten percent off $59.99 is 53.991, a total no checkout should print, and only a test that named the cent would have caught it. Then comes the refactor: the rule moves into a table, so a second discount code would be one more line, and the four tests run unchanged and stay green.
With all four tests in place, test/discount.test.js reads:
const { applyDiscount } = require('../src/discount');
test('SAVE10 takes 10% off an $80 cart', () => {
expect(applyDiscount(80, 'SAVE10')).toEqual({ total: 72, message: 'SAVE10 applied' });
});
test('SAVE10 needs a $50 minimum spend', () => {
expect(applyDiscount(40, 'SAVE10')).toEqual({ total: 40, message: 'Spend $50 or more to use SAVE10' });
});
test('an unknown code changes nothing', () => {
expect(applyDiscount(80, 'FREESHIP')).toEqual({ total: 80, message: 'Code not recognized' });
});
test('the discount rounds to the cent', () => {
expect(applyDiscount(59.99, 'SAVE10').total).toBe(53.99);
});
And src/discount.js after the refactor:
const CODES = {
SAVE10: { percent: 10, minimum: 50 },
};
function applyDiscount(subtotal, code) {
const rule = CODES[code];
if (!rule) return { total: subtotal, message: 'Code not recognized' };
if (subtotal < rule.minimum) {
return { total: subtotal, message: `Spend $${rule.minimum} or more to use ${code}` };
}
const total = Math.round(subtotal * (100 - rule.percent)) / 100;
return { total, message: `${code} applied` };
}
module.exports = { applyDiscount };
TLDR: four tests, four reds, four small greens and one refactor. Every rule in the code exists because a test asked for it, and only a developer ever had to read those tests.
BDD on the Same Code: Scenarios First, Then Glue
BDD starts one step earlier, in a conversation. Someone from product, someone from QA and a developer agree on examples, and the examples go into a feature file in Gherkin, which Cucumber’s reference says “uses a set of special keywords to give structure and meaning to executable specifications.” Install Cucumber.js with npm install --save-dev @cucumber/cucumber and save the agreement about SAVE10 as features/discount.feature:
Feature: Discount codes at checkout
Shoppers can enter a code to take money off their order.
Scenario: A valid code takes 10% off
Given a cart worth $80.00
When the shopper applies the code "SAVE10"
Then the total is $72.00
Scenario: Small carts can't use SAVE10
Given a cart worth $40.00
When the shopper applies the code "SAVE10"
Then the total is $40.00
And the shopper sees "Spend $50 or more to use SAVE10"
Scenario: An unknown code changes nothing
Given a cart worth $80.00
When the shopper applies the code "FREESHIP"
Then the total is $80.00
And the shopper sees "Code not recognized"
Run npx cucumber-js in a project with only that file and nothing has failed an assertion yet. Every step is undefined, and Cucumber writes the start of the glue for you. Trimmed, the output reads:
3 scenarios (3 undefined)
11 steps (11 undefined)
You can implement missing steps with the snippets below:
Given('a cart worth ${float}', function (float) {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
The glue is the extra layer. A step definition file maps each distinct phrase in the scenarios to the code it runs. Four entries cover all eleven steps, in features/step_definitions/discount.steps.js:
const { Given, When, Then } = require('@cucumber/cucumber');
const assert = require('node:assert');
const { applyDiscount } = require('../../src/discount');
Given('a cart worth ${float}', function (subtotal) {
this.subtotal = subtotal;
});
When('the shopper applies the code {string}', function (code) {
this.result = applyDiscount(this.subtotal, code);
});
Then('the total is ${float}', function (total) {
assert.strictEqual(this.result.total, total);
});
Then('the shopper sees {string}', function (message) {
assert.strictEqual(this.result.message, message);
});
Now the run is red, with Cannot find module '../../src/discount', because the code doesn’t exist yet. Write it, test-first or not. We dropped in the function the TDD loop produced, and the result was 3 scenarios (3 passed) and 11 steps (11 passed).
Here is where the extra layer pays for itself. Say a support lead reads the feature file and asks what happens when a shopper types the code in lower case, because shoppers do. They can add a scenario using only phrases that already exist, without writing any code. We added it, and the run failed. The scenario and the trimmed output:
Scenario: Codes work in lower case
Given a cart worth $80.00
When the shopper applies the code "save10"
Then the total is $72.00
Failed scenarios:
1) Codes work in lower case # features\discount.feature:21
Then the total is $72.00
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
80 !== 72
4 scenarios (3 passed, 1 failed)
14 steps (13 passed, 1 failed)
The developer’s four Jest tests never asked about case, so the code needed one new line, const key = code.toUpperCase();, with key used in place of code below it. After that, Cucumber reports 4 scenarios (4 passed) and 14 steps (14 passed), and the four Jest tests still pass against the same file.
TLDR: the scenarios cost 19 lines of step definitions. In exchange, a new rule went in as plain words, built from phrases that already existed, with no new glue.
Which Is Better? Ask Who Reads the Test
Neither one wins on its own terms. The run shows what each one costs and buys. TDD’s loop is shorter, with no translation layer and a failure that points at one function. BDD adds a file of glue, and in exchange the rules sit where people who don’t write code can read them, challenge them and add to them. So decide by who reads the test:
| If the test’s readers are | Start with |
|---|---|
| Developers only, on logic like pricing, parsing or algorithms | TDD |
| Product, support or QA, on rules they own and can get wrong | BDD, with TDD underneath |
| A regulator or an auditor who needs the rules in words | BDD, kept short |
| Nobody outside the team, but the feature file keeps going stale | TDD, and drop the glue |
The second row is where our example ended up, with scenarios on top and the Jest tests underneath. In that setup a scenario fails first, then unit tests drive the code that makes it pass.
“Is Cucumber TDD or BDD?” has a short answer: Cucumber is a BDD tool. It runs the scenarios and hands each step to whatever drives the app underneath, so Cucumber and Selenium were never rivals.
TDD is not going anywhere either. In Augmented Coding: Beyond the Vibes (June 2025), Kent Beck describes building a B+ tree library with an AI coding agent and trying to get the agent to use TDD, while watching for signs it was cheating by disabling or deleting tests. His account puts the failing test back at the front of the loop, as the check on code a person didn’t type.
Tools for Each Loop
For TDD, use the unit test runner your language already has: Jest or Vitest for JavaScript, pytest for Python, JUnit for Java. For BDD, Cucumber is the reference runner. The Cucumber installation page lists official implementations for JavaScript, Java, Kotlin, Scala, Ruby and C++, plus semi-official ones such as Behave and pytest-bdd for Python, Behat for PHP and Reqnroll for .NET. Both loops leave behind test automation that runs on every commit, and upkeep is the cost that lasts.
Our scenarios call applyDiscount directly. A suite that drives a real API or a browser calls an API client, one of the tools sorted in our guide to integration testing software, or a browser framework from its step definitions. Where that framework runs the test, inside the tab or outside it, is the split behind both Cypress vs Selenium and Playwright vs Cypress, and it decides what your step definitions can reach.
Plain-Language Tests Without the Glue
Go back to the lower-case scenario. The valuable part was that a rule could go in as plain words, from anyone who can read the feature file. The cost was the step-definition file sitting between those words and the code, 19 lines for 4 phrases, which grows with every new phrase.
Pie works at the level a BDD scenario describes, on the running app instead of the function. As an agentic testing platform, Pie starts by exploring the app a shopper uses, web or mobile, and generates tests from what it finds. Your team adds more by describing them in Pie Chat, in the same plain words a scenario uses.
The support lead’s next rule goes in as a sentence, with no step file behind it. Your TDD unit tests stay in the repo, testing the logic the way they did above.
Pick the Reader, Then the Loop
One function passed both suites. What differed was who could read the test, and that decided who caught which bug: a developer’s test caught the stray third decimal, and the lower-case code fell to a scenario anyone who reads the feature file could have written.
Decide who needs to read the test before you pick the tool. If it’s only developers, run TDD and skip the glue. If someone outside engineering owns the rules, write the scenario with them first, and keep TDD underneath for the code.
Test the Checkout Your Scenarios Describe
Hand Pie the app your scenarios describe. It finds the flows, generates the tests and runs them, with no step definitions to keep in sync.