Notes
The idea
BDD starts with a conversation, not a tool. Three viewpoints meet before a story is built, often called the three amigos: business, who knows the rule; development, who knows how it could work; and testing, who asks what could go wrong and what happens at the edges. The output is a set of rules with concrete examples. Teams that skip the conversation and only use the tool usually end up with slow UI tests written in a strange language.
- business: what problem, what rule? (product owner)
- developer: how could it work, what is hard?
- tester: what could go wrong, what about the edges?
- output: rules + examples, BEFORE coding starts
Example mapping
A simple technique for the conversation is example mapping. Write the story, then each rule under it, then concrete examples under each rule, and any open questions. For ShopRung's coupon: SAVE10 needs fifty dollars; three notebooks, thirty seven fifty, is refused; four, exactly fifty, is accepted. Codes ignore case. And a question: does shipping count toward the fifty? Answering that before coding is much cheaper than finding it in testing.
- story: coupons at checkout
- rule: SAVE10 needs $50.00 e.g. $37.50 → refused e.g. $50.00 → accepted
- rule: codes ignore case e.g. "save10" works
- question: does shipping count toward the $50.00? (no)
Gherkin
Gherkin turns those examples into a file that a tool can run. A feature names the capability. Background holds steps every scenario shares: the shop has its seed data and Alice is logged in. Each scenario is one example: given a starting state, my cart has four notebooks; when an action happens, I apply save ten; then outcomes, the discount is five dollars and the total is forty nine ninety nine. And and But continue the previous kind of step.
Feature: Coupons at checkout
Background:
Given the shop has its seed data
And I am logged in as "alice@..."
Scenario: SAVE10 applies at $50.00
Given my cart has 4 "Clean Code
Notebook"
When I apply the coupon "save10"
Then the discount is "$5.00"
And the total is "$49.99" Outlines
When the same behaviour needs several data points, use a scenario outline. The steps contain placeholders in angle brackets, and an examples table gives one row per run: three notebooks refused, four accepted, five accepted. That is boundary value analysis, written so the product owner can read and check it. Each row becomes its own scenario in the report.
Scenario Outline: SAVE10 needs $50
Given my cart has <quantity> ...
When I apply the coupon "SAVE10"
Then the coupon is <result>
Examples:
| quantity | result |
| 3 | refused |
| 4 | accepted |
| 5 | accepted | Step definitions
Gherkin alone does nothing. Step definitions connect each sentence to code. A pattern like I apply the coupon, followed by a string parameter, matches the sentence and passes save ten to a function that posts to ShopRung's coupon endpoint. Another step checks the total. Cucumber expressions such as string and int extract the values. Java, JavaScript, Python and other languages all have Cucumber style tools; the next episode does it in Java.
When('I apply the coupon {string}',
async function (code) {
this.last = await call(this,
'POST', '/api/cart/coupon',
{ code });
});
Then('the total is {string}',
function (s) {
assert.equal(this.last.json
.total, s); }); A real run
We ran this feature with Cucumber against ShopRung. Four scenarios, twenty one steps, all passed. Then we switched on the coupon boundary bug. Two scenarios failed: the exact fifty dollar scenario, at the discount step, and the four notebook row of the outline. The three and five notebook rows still passed. The failure is reported in the same sentences the business agreed on, which is the point.
4 scenarios (4 passed) 21 steps (21 passed) bug "coupon-boundary" on: ✖ Then the discount is "$5.00" ✖ Then the coupon is accepted (the 4-notebook row) 4 scenarios (2 failed, 2 passed)
Good Gherkin
Good Gherkin is declarative. Bad scenarios describe clicks: when I click the coupon field, type save ten, click apply. That breaks with every UI change and hides the rule. Good scenarios say what, not how: when I apply the coupon save ten. Keep one behaviour per scenario, use the business's own words, and keep incidental details out. The same scenario could then run through the API or the UI.
- bad (imperative): When I click "#coupon" And I type "save10" And I click the Apply button
- good (declarative): When I apply the coupon "save10"
- one behaviour per scenario
- no UI words, no test data noise
When it helps
When does BDD help? When business people really read and agree on the scenarios, and when the domain has rich rules, like pricing, eligibility or workflows. It costs more than it gives when only testers ever read the feature files, or when every test, even purely technical ones, is forced into Gherkin. Then plain JUnit or pytest tests are simpler. Be honest about that in interviews: it shows judgment.
- helps when: business people read and agree on the scenarios rules are rich (pricing, eligibility, workflows)
- costs when: only testers ever read them every test is forced into Gherkin, even technical ones
Common mistakes
BDD mistakes. Writing Gherkin after the code, alone, as just another test format. Click by click scenarios. One scenario checking five rules. Giant backgrounds nobody reads. Many phrasings for the same step, like I log in and the user logs in, each with its own code. And running every scenario through the UI, when most rules can be checked faster through the API.
- Gherkin written AFTER the code, by testers alone
- click-by-click scenarios
- one scenario testing 5 rules
- giant Backgrounds
- duplicate step phrasings ("I log in", "user logs in")
- all of BDD through the UI
Say it like this
In the interview: BDD means agreeing on behaviour through concrete examples with business and development before coding, using the three amigos and example mapping. The examples become Gherkin scenarios, declarative, one rule each, with outlines for data, and Cucumber runs them through step definitions, preferably through the API where possible. It works when the business really reads the scenarios; otherwise plain tests are simpler.
- "BDD is agreeing on behaviour
- through examples with business
- and devs, before coding: three
- amigos, example mapping. The examples become Gherkin
- scenarios, declarative and one rule each, and Cucumber runs
- them via step definitions. It
- works when the business really
- reads them."