Cucumber and BDD interview questions check whether you can describe behaviour in plain language and link it to automated tests. Expect questions on the BDD idea, Gherkin keywords, feature files, step definitions, Scenario Outline, hooks and tags. This page has 25 questions with short answers and examples using Cucumber with Java.
Step definition snippets assume the io.cucumber Java and JUnit or TestNG dependencies are in your project. They show only the useful part of each class.
How to answer Cucumber and BDD questions
Answer with the idea, a Gherkin line and the code behind it. "A step definition links a Gherkin step to Java code. When the user enters a valid password matches a method annotated with @When, which types the password using Selenium."
Pro tip: Interviewers often ask you to write a scenario on the spot. Practise writing a login scenario and a Scenario Outline with an Examples table until it takes under two minutes.
BDD basics questions
Q1. What is BDD?
30-second answer: Behaviour-Driven Development is a way of working where the product owner, developers and testers agree on how a feature should behave using concrete examples in plain language. Those examples become automated tests, so the requirement and the test stay the same document.
Q2. What are the benefits of BDD?
30-second answer: Everyone, including non-technical people, can read the scenarios. Misunderstandings come out before coding starts. The scenarios serve as living documentation that is checked on every run. The main risk is writing scenarios only as test scripts without the team discussion, which loses most of the benefit.
Q3. What is the difference between TDD and BDD?
| Point | TDD | BDD |
|---|---|---|
| Focus | Code works as the developer intends | Software behaves as the business expects |
| Written by | Developers | Product owner, developer and tester together |
| Language | Programming language | Plain language (Gherkin) plus code |
| Level | Usually unit tests | Usually feature or acceptance tests |
30-second answer: TDD writes a failing unit test first, then the code. BDD grew out of TDD and describes behaviour from the user's side in language the whole team understands.
Q4. What are the three amigos?
30-second answer: A short meeting where a business person (such as a product owner), a developer and a tester discuss a story and agree on examples before work starts. The examples become Gherkin scenarios.
Q5. What is Cucumber?
30-second answer: Cucumber is an open-source tool that runs BDD scenarios written in Gherkin as automated tests. It reads feature files, matches each step to a step definition in code and reports which scenarios passed or failed. Cucumber supports Java, JavaScript and other languages.
Gherkin and feature file questions
Q6. What is Gherkin?
30-second answer: Gherkin is the plain-language format Cucumber reads. It uses keywords such as Feature, Scenario, Given, When, Then, And and But, one step per line. Gherkin is available in many spoken languages, though English is most common.
Q7. What is a feature file? Write one.
Feature: Login
As a registered user
I want to log in
So that I can see my orders
Scenario: Successful login with valid credentials
Given the user is on the login page
When the user enters email "asha@example.com" and password "Valid@123"
And clicks the login button
Then the dashboard is shown
And the welcome message contains "Asha"
30-second answer: A feature file has the .feature extension and describes one feature with one or more scenarios. The lines under Feature are a free-text description; Cucumber does not run them.
Q8. What do Given, When and Then mean?
| Keyword | Purpose | Example |
|---|---|---|
| Given | Starting state or context | Given the cart has 2 items |
| When | The action or event | When the user applies coupon "SAVE10" |
| Then | The expected outcome | Then the total is reduced by 10% |
| And, But | Continue the previous keyword | And a success message is shown |
30-second answer: Given sets up, When acts, Then checks. Cucumber treats them the same when matching code; the keywords are for readers.
Q9. What makes a good scenario?
30-second answer: It describes one behaviour, uses business language instead of UI details, has one When and a clear Then, and is short, usually under ten steps. "When the user logs in with valid details" is better than "When the user clicks the text box with id email and types".
Q10. What is Background?
Background:
Given the user is logged in
And the cart is empty
Scenario: Add one product
When the user adds "Wireless Mouse" to the cart
Then the cart shows 1 item
30-second answer: Background holds steps that run before every scenario in the file. It removes repetition. Keep it short, and use it only for steps every scenario truly needs.
Q11. What is a Scenario Outline?
Scenario Outline: Login with different credentials
Given the user is on the login page
When the user enters email "<email>" and password "<password>"
Then the message "<message>" is shown
Examples:
| email | password | message |
| asha@example.com | Valid@123 | Welcome, Asha |
| asha@example.com | wrong | Invalid email or password |
| | Valid@123 | Email is required |
30-second answer: A Scenario Outline runs the same steps once for each row of the Examples table. Values in angle brackets are replaced by the matching column. This is BDD's way of writing data-driven tests.
Q12. What is the difference between a Scenario Outline and a data table?
30-second answer: A Scenario Outline runs the whole scenario once per Examples row. A data table passes a table of values into a single step, and the scenario runs once.
Given the following users exist:
| name | city |
| Asha | Hyderabad |
| Ravi | Pune |
The step definition receives the table as a DataTable, which can be read as a list of maps.
Step definition questions
Q13. What is a step definition?
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;
public class LoginSteps {
@Given("the user is on the login page")
public void openLoginPage() {
loginPage.open();
}
@When("the user enters email {string} and password {string}")
public void enterCredentials(String email, String password) {
loginPage.login(email, password);
}
@Then("the dashboard is shown")
public void dashboardShown() {
Assert.assertTrue(dashboardPage.isDisplayed());
}
}
30-second answer: A step definition is a method whose annotation text matches a Gherkin step. When Cucumber reads the step, it runs that method. loginPage and dashboardPage here are page objects that hold the Selenium code.
Q14. What are Cucumber expressions?
30-second answer: Cucumber expressions capture values from steps with placeholders such as {string}, {int}, {float} and {word}. the cart has {int} items matches "the cart has 3 items" and passes 3 as an int. Regular expressions also work, but Cucumber expressions are simpler to read.
Q15. What happens if a step has no matching step definition?
30-second answer: Cucumber reports the step as undefined and prints a code snippet you can paste to create the missing method. The scenario does not pass. If two step definitions match the same step, Cucumber reports an ambiguous step error.
Q16. Can one step definition be reused across feature files?
30-second answer: Yes. Step definitions are global within the glue path, so "Given the user is logged in" written once can be used in every feature file. This is why steps should be written in general business language, not tied to one scenario.
Q17. How do you share data between steps in different classes?
30-second answer: Use dependency injection. With the cucumber-picocontainer dependency, Cucumber creates one shared context object per scenario and passes it to the constructors of all step classes. Avoid static variables, because they leak data between scenarios and break parallel runs.
Hooks, tags and runner questions
Q18. What are hooks in Cucumber?
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;
public class Hooks {
@Before
public void setUp() {
DriverFactory.start();
}
@After
public void tearDown(Scenario scenario) {
if (scenario.isFailed()) {
byte[] shot = DriverFactory.screenshot();
scenario.attach(shot, "image/png", "failure");
}
DriverFactory.quit();
}
}
30-second answer: @Before runs before each scenario and @After after each one, even if it failed. They are used to start and stop the browser and attach screenshots of failures to the report. @BeforeStep and @AfterStep run around each step. DriverFactory here is your own helper class.
Q19. What are tags, and how do you use them?
@smoke @login
Scenario: Successful login with valid credentials
30-second answer: Tags group scenarios or whole features. You run a subset with a tag expression, such as @smoke, @smoke and not @wip, or @login or @cart. Tags can also limit hooks, as in @Before("@db").
Q20. What is a test runner in Cucumber?
import org.junit.platform.suite.api.*;
import static io.cucumber.junit.platform.engine.Constants.*;
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "steps")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty, html:target/cucumber.html")
@ConfigurationParameter(key = FILTER_TAGS_PROPERTY_NAME, value = "@smoke")
public class RunCucumberTest {
}
30-second answer: The runner tells Cucumber where the feature files and step definitions (glue) are, which plugins to use for reports and which tags to run. This example uses the JUnit Platform. Older projects use @RunWith(Cucumber.class) with @CucumberOptions on JUnit 4, and TestNG projects extend AbstractTestNGCucumberTests.
Q21. What do the main runner options mean?
| Option | Meaning |
|---|---|
| features | Folder of .feature files |
| glue | Package of step definitions and hooks |
| plugin | Report formats, such as pretty, html, json |
| tags | Tag expression to choose scenarios |
| dryRun | Check that every step has a definition without running them |
| monochrome | Plainer console output (older option) |
30-second answer: features and glue are the essentials. Use dryRun to find undefined steps quickly after writing new feature files.
Q22. What reports can Cucumber produce?
30-second answer: Built-in plugins create pretty console output, HTML, JSON and JUnit XML reports. Teams often add tools such as Allure or a Cucumber HTML reporting plugin for nicer reports with screenshots. CI tools read the JUnit XML to show results.
Practice and design questions
Q23. How does Cucumber fit into a Selenium framework?
30-second answer: Feature files describe behaviour. Step definitions call page object methods. Page objects hold Selenium locators and actions. Hooks start and stop the browser and attach screenshots. A runner chooses the features and tags, and Maven runs it all in CI. The Selenium interview questions page covers the Selenium side.
Q24. What are common mistakes when writing Cucumber tests?
30-second answer: Writing UI steps such as "click the button with id submit" instead of behaviour; very long scenarios; scenarios that depend on each other; duplicate steps that differ only in wording; using static variables for shared data; and treating Cucumber as a test script tool without involving the business at all.
Q25. When should you not use Cucumber?
30-second answer: When nobody outside the test team reads the feature files, the extra Gherkin layer adds work without much benefit. Low-level checks, such as API field validations or unit tests, are usually clearer in plain TestNG or JUnit. Cucumber pays off when business people actually review the scenarios.
Quick revision table
| Term | One line to remember |
|---|---|
| BDD | Agree on behaviour through examples |
| Gherkin | Plain-language format: Given, When, Then |
| Feature file | .feature file with scenarios |
| Step definition | Code linked to a Gherkin step |
| Background | Steps before every scenario in a file |
| Scenario Outline | Same steps, one run per Examples row |
| Data table | Table passed into one step |
| Hooks | @Before, @After around scenarios |
| Tags | Choose which scenarios run |
How to prepare in one week
| Day | Task |
|---|---|
| 1 | BDD idea, Gherkin keywords, write three scenarios |
| 2 | Maven project with Cucumber, first step definitions |
| 3 | Parameters, Scenario Outline and data tables |
| 4 | Background, hooks and screenshots |
| 5 | Tags and the runner, HTML report |
| 6 | Connect to Selenium page objects |
| 7 | Revise and do a mock interview |
Cucumber runs on top of a test runner, so revise the TestNG interview questions for freshers too. Good scenarios start from good test cases, which the test case writing interview questions page explains.

