Cucumber and BDD interview questions and answers for testers
Cucumber interview questions check two things: whether you can write Gherkin that business people can read and that stays stable as the product changes, and whether you can build the code behind it (step definitions, hooks, shared state, runners and reports) without turning the suite into a slow, flaky tangle. Expect syntax questions, a scenario to write or critique, and senior questions on when BDD is worth its overhead at all.
By Evin JohnPublished 8 min read
How Cucumber shows up in interviews
Cucumber comes up in test automation, SDET and QA lead interviews, and sometimes for developers on teams that write acceptance tests together. The tool itself is small, so interviewers move quickly from syntax to judgment: is this scenario describing behavior or clicking buttons, why does this step match two definitions, how do two step classes share a logged-in user. Cucumber usually drives something else underneath, most often a browser driver or an API client, so expect the follow-ups covered in Selenium interview questions.
- Explain BDD and GherkinWhat behavior-driven development is for, who reads feature files, and the keywords.
- Write or fix a scenarioTurn a user story into one or two scenarios, or rewrite an imperative scenario full of clicks into a declarative one.
- Glue and frameworkStep definitions, parameter types, hooks, tags, state sharing, how the suite runs in CI and how failures are reported.
- Maintenance and judgmentA slow or flaky suite, duplicated steps, a product owner who never reads the features. What do you change?
Cucumber and Gherkin fundamentals
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What is the difference between BDD and Cucumber? | Concepts | BDD is a collaboration practice: agree on behavior through concrete examples before building. Cucumber is one tool that turns those examples into executable tests. You can do BDD without Cucumber and use Cucumber without doing BDD. |
| What is Gherkin? | Syntax | The plain-language format of feature files: Feature, Rule, Background, Scenario (or Example), Scenario Outline with Examples, and steps starting with Given, When, Then, And or But. |
| What do Given, When and Then mean? | Step roles | Given sets up context, When is the action under test, Then checks the outcome. Cucumber treats the keywords the same when matching; the split is for readers. |
| What is a step definition? | Glue | Code bound to a step's text by an expression. When a step runs, Cucumber finds the one matching definition and calls it with the captured values. |
| What does Background do? | Shared setup | Steps that run before every scenario in the feature (or rule). Keep it short and about context the reader needs; long backgrounds hide what each scenario depends on. |
| Scenario versus Scenario Outline? | Data-driven | A Scenario runs once. An Outline is a template with <placeholders> that runs once per row of its Examples table. |
| What are tags used for? | Selection | Labels such as @smoke or @wip on features or scenarios, used to choose what runs and to scope hooks. |
| Undefined, pending, ambiguous and skipped steps? | Statuses | Undefined: no definition matches. Pending: a definition exists but marks itself unfinished. Ambiguous: more than one definition matches. Skipped: an earlier step in the scenario failed. |
| What is a dry run? | Tooling | Matching every step to a definition without executing anything, a fast check for undefined or ambiguous steps in CI. |
| Can feature files be written in other languages? | i18n | Yes, Gherkin keywords are translated into many languages and chosen with a # language: header at the top of the file. |
Intermediate: steps, tables, outlines and hooks
Feature: Loyalty discounts at checkout
Rule: Members get a discount once their basket passes the threshold
Background:
Given the loyalty threshold is 50.00
Scenario: Member above the threshold gets the discount
Given a member with this basket:
| item | price |
| headphones | 45.00 |
| cable | 12.00 |
When they check out
Then the order total is 51.30
Scenario Outline: Non-members never get the discount
Given a guest with a basket worth <basket>
When they check out
Then the order total is <total>
Examples:
| basket | total |
| 40.00 | 40.00 |
| 80.00 | 80.00 |const { Given, When, Then, Before, setWorldConstructor } = require("@cucumber/cucumber");
const assert = require("node:assert/strict");
class ShopWorld {
constructor() {
this.threshold = 0;
this.basket = [];
this.member = false;
}
}
setWorldConstructor(ShopWorld);
Before({ tags: "@clean-db" }, async function () {
// reset test data only for scenarios tagged @clean-db
});
Given("the loyalty threshold is {float}", function (amount) {
this.threshold = amount;
});
Given("a member with this basket:", function (table) {
this.member = true;
this.basket = table.hashes().map((r) => Number(r.price));
});
Given("a guest with a basket worth {float}", function (amount) {
this.basket = [amount];
});
When("they check out", function () {
const sum = this.basket.reduce((a, b) => a + b, 0);
const discounted = this.member && sum > this.threshold ? sum * 0.9 : sum;
this.total = Math.round(discounted * 100) / 100;
});
Then("the order total is {float}", function (expected) {
assert.equal(this.total, expected);
});- Cucumber Expressions or regular expressions? Expressions such as
{int},{float},{string}and{word}are easier to read and convert types for you. Regular expressions are still supported for odd formats; custom parameter types are cleaner when the same pattern (a date, a currency) appears in many steps. - How do you read a data table in a step? As a list of maps keyed by the header row (
hashes()in cucumber-js, a list of maps or typed objects in Cucumber-JVM), as raw rows, or as a key-value map for two-column tables. Name the shape before choosing. - When is an Outline the wrong tool? When the rows test different behaviors rather than the same behavior with different data, or when the table grows to dozens of rows that no reader will check. Split it, or move the data into a lower-level test.
- What hooks exist and what belongs in them? Before and After run around each scenario, often with tag filters; some implementations also have step-level and run-level hooks. Put technical setup there (browser, test data cleanup, screenshots on failure), never business steps a reader needs to see.
- How do tag expressions work? Boolean expressions such as
@smoke and not @wipor(@api or @ui) and not @slow, passed on the command line or in config. They select scenarios and can scope hooks. - What is a doc string? A multi-line argument between triple quotes, used for a JSON body or an email text that a step needs whole.
- Why does the same step text match two definitions? Two expressions are too broad, for example
I click {string}andI click {string} button. Make the wording specific or merge them; ambiguity is reported, not silently resolved.
Framework, state and CI questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| How do steps in different classes share state in Cucumber-JVM? | DI | Through a dependency injection module (PicoContainer, Spring or Guice). Each scenario gets fresh instances, and a shared context object is injected into every step class that needs it. Static fields leak state between scenarios. More on the mechanics in dependency injection interview questions. |
| What is the World in cucumber-js? | State | A new object created for each scenario and bound to this in steps and hooks. A custom World class holds the driver, API client and scenario data. |
| How do you run Cucumber from JUnit 5? | Runners | Through the JUnit Platform engine for Cucumber, with a suite class selecting the feature path and glue package, or with configuration properties. Older projects use a JUnit 4 runner with an options annotation. |
| How do you run scenarios in parallel? | Speed | Cucumber-JVM can run scenarios in parallel through the JUnit Platform or TestNG; cucumber-js has a parallel worker option. It only works if scenarios do not share mutable state, test accounts or data. |
| Which reports do teams produce? | Reporting | HTML for people, JSON or the message format for tools, JUnit XML for CI dashboards. Attach screenshots or response bodies on failure through the hook's attach function. |
| How do you rerun only failed scenarios? | Flakiness | A rerun formatter writes failed scenario locations to a file that a second run consumes, or the runner's retry option. Treat reruns as a signal to fix, not a permanent crutch. |
| Where should waits and page logic live? | Layering | Below the steps, in page objects or API clients. Steps should read like the scenario and call one or two methods each. |
| How do you keep step definitions from multiplying? | Maintenance | Search before adding a step, organize step files by domain concept rather than by feature file, and prefer a few well-parameterized steps over near-duplicates. |
Senior and scenario questions
- Rewrite this scenario: Given I open the login page, When I type "anna" into username, And I type "pw" into password, And I click Login, Then I see Welcome. Make it declarative:
Given Anna is a registered customer/When she signs in/Then she sees her account overview. The clicks move into step code, and the scenario survives a redesign of the login form. - Product owners never read the feature files. Is the suite still worth it? Then Cucumber is acting as a verbose test runner. Either bring the files into refinement (three amigos or example mapping sessions, where business, development and testing agree on rules and examples) or consider plain tests in code, which are cheaper to maintain.
- The UI suite takes two hours. Where do you start? Measure which scenarios are slowest, move setup from the UI to APIs or direct data seeding, push detailed rule checks down to unit or API tests and keep a thin layer of end-to-end scenarios, then parallelize what remains.
- One scenario fails about once a week. How do you approach it? Collect the failure artifacts across runs, look for timing (missing waits), shared data between scenarios, or order dependence. Run it in a loop locally and alone versus with others to tell them apart; see automation testing interview questions for quarantine policy.
- Should every acceptance criterion become a scenario? No. Scenarios are for examples that clarify behavior people might disagree on. Edge cases that are purely technical usually belong in faster, lower-level tests.
- How do you test an API with Cucumber without leaking HTTP details into Gherkin? Steps describe the business action and outcome; the step code builds requests, and a doc string appears only when the payload itself is what the business cares about.
- How do you structure features in a large product? By capability or domain, not by sprint or ticket number, with a Rule per business rule. Tags mark suite membership and ownership, not every possible attribute.
Fictional example
- Interviewer
- You mentioned your team trimmed its Cucumber suite. Why, and what did you keep?
- Candidate
- We had about four hundred UI scenarios, many written after the code by testers alone, and mostly imperative steps. Nobody outside QA read them, and a checkout redesign broke a third of them in one sprint. We kept Cucumber for the rules that product and support argue about, such as discounts, refunds and account limits, rewrote those scenarios declaratively in example mapping sessions, and drove most of them through the API. Pure validation cases moved to unit and API tests in code. The suite got shorter, ran faster, and refinement meetings started opening the feature files, which was the point of having them.
How to prepare for a Cucumber interview
- Days 1 and 2: set up a small project in the language the job uses, write three scenarios for a feature you know, and see undefined, pending and ambiguous steps on purpose.
- Day 3: add a data table, an Outline and a tagged hook. Run only
@smokefrom the command line. - Day 4: share state between two step files with the World (JavaScript) or a DI module (Java), and explain why statics are a trap.
- Day 5: wire the suite into a CI job with JUnit XML and an HTML report, and attach a screenshot or response on failure.
- Days 6 and 7: take three imperative scenarios and rewrite them declaratively, then practice explaining when you would not use Cucumber at all.
Scenario-writing questions are judged on wording, and it is hard to hear your own wording while you are talking. Natively, an AI interview assistant for Mac and Windows, transcribes a mock automation interview on your computer so you can reread the Gherkin you dictated. When practicing it can read a feature file or a failing report from a screenshot and suggest improvements, help with step code, and with Pro or the free trial use your résumé and the job description you add. Transcripts and notes are saved to go over later.
Questions people ask
What Cucumber questions are asked in interviews?
BDD versus Cucumber, Gherkin keywords, step definitions and Cucumber Expressions, Background, Scenario Outline and data tables, hooks and tag expressions, sharing state between steps, runners, reports and how to keep scenarios declarative.
What is the difference between Scenario and Scenario Outline?
A Scenario runs once with fixed values. A Scenario Outline is a template with placeholders that runs once for each row of its Examples table.
How do you share data between step definitions in Cucumber?
In cucumber-js, store it on the World object for the scenario. In Cucumber-JVM, inject a shared context object into step classes through a DI module such as PicoContainer or Spring. Avoid static fields.
Is Cucumber the same as BDD?
No. BDD is a way of agreeing on behavior through examples before building; Cucumber is a tool that runs those examples as tests. You can practice BDD without Cucumber.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
