Interview questions · Tech stack

Cucumber Interview Questions & Answers (2026)

These interviews test your grasp of BDD fundamentals, ability to write clear Gherkin scenarios, and skill in integrating Cucumber with Java or other languages. Demonstrate practical knowledge of hooks, data tables, and parallel execution. Show how you troubleshoot flaky steps and maintain reusable step libraries to impress interviewers.

24 questions · updated Aug 29, 2026

Quick facts

Typical roundsPhone screen, technical coding, BDD design, and final on‑site with live Cucumber exercise
Core language supportJava, JavaScript, Ruby, Python, .NET
Key librariesCucumber‑JVM, Cucumber‑JS, Cucumber‑Ruby, Cucumber‑Py
Common toolsJUnit/TestNG, Maven/Gradle, Selenium, RestAssured
Typical experience level2–5 years of automated testing with BDD

Questions

Beginner

What is BDD and how does Cucumber support it?

Behavior‑Driven Development (BDD) encourages collaboration by describing software behavior in plain language that both technical and non‑technical stakeholders can understand. Cucumber implements BDD by parsing Gherkin feature files written in a Given‑When‑Then format and linking each step to executable code via step definitions. This separation lets product owners define acceptance criteria while developers deliver automated verification, ensuring that the test suite stays aligned with business expectations.

GoogleAmazon

Explain the structure of a Gherkin feature file.

A Gherkin feature file starts with a Feature keyword describing the high‑level functionality, followed by an optional Background that runs before each Scenario. Each Scenario contains a series of steps prefixed with Given, When, Then, And, or But, representing preconditions, actions, and expected outcomes. Tags (e.g., @smoke) can be added above Feature or Scenario for selective execution. Proper indentation and clear wording are essential for readability and maintainability.

Microsoft

How do you write a step definition in Java for a Cucumber scenario?

In Java, a step definition is a method annotated with @Given, @When, or @Then that includes a regular expression matching the Gherkin step text. The method receives captured groups as parameters, allowing you to interact with the application under test. For example, @Given("^the user is on the login page$") public void navigateToLogin() { driver.get("/login"); } This binds the textual step to executable code, enabling Cucumber to invoke it during test runs.

Netflix

What is the difference between Scenario Outline and Examples in Gherkin?

Scenario Outline allows you to define a template scenario with placeholders marked by < >. The Examples table provides concrete values for those placeholders, generating multiple scenario instances from a single outline. This reduces duplication when testing the same flow with different data sets. Each row in the Examples table becomes a separate scenario execution, enabling clear reporting of which data set passed or failed.

Facebook

What are tags in Cucumber and how do you use them to control test execution?

Tags are @ annotations placed above Feature or Scenario lines. They enable selective execution via the command line or build tool configuration. For example, @smoke runs only smoke tests, while @skip can exclude scenarios. In Maven, you can set cucumber.options="--tags @smoke and not @skip". Tags also help organize tests by priority, component, or environment, providing flexibility in CI pipelines.

Salesforce

How do you generate HTML reports from Cucumber runs?

Cucumber includes built‑in HTML reporting via the plugin option. In Maven, add -Dcucumber.plugin=html:target/cucumber-report.html to the command line or configure surefire plugin. The generated report lists features, scenarios, steps, and their pass/fail status, with embedded screenshots if added in hooks. For richer reports, integrate with ExtentReports or Allure by adding the respective plugin dependency and specifying the plugin path.

eBay

What is the difference between a Step Definition and a Hook in Cucumber?

A Step Definition maps a Gherkin step to executable code, directly representing an action or verification in the scenario. A Hook is a method that runs automatically before or after scenarios or steps, handling setup, teardown, or cross‑cutting concerns. Steps drive the business flow; hooks manage test environment concerns. Both are annotated, but hooks use @Before/@After while steps use @Given/@When/@Then.

Intel

Intermediate

What are Cucumber hooks and when would you use them?

Hooks are special methods annotated with @Before, @After, @BeforeStep, or @AfterStep that run at defined points in the test lifecycle. Use @Before to set up test data, initialize browsers, or start mock servers before each scenario. @After cleans up resources, closes browsers, or resets configurations. @BeforeStep/@AfterStep are useful for fine‑grained actions like logging each step or taking screenshots on failure. Proper hook usage reduces duplication and ensures consistent test environments.

Adobe

How can you share state between step definitions without using static variables?

Cucumber supports dependency injection via PicoContainer, Spring, or Guice. By defining a POJO (e.g., a World class) and annotating it with @Inject, Cucumber creates a single instance per scenario, allowing steps to share data through its fields. This avoids static state, keeps scenarios isolated, and makes tests thread‑safe. Example: @Inject private World world; then world.setUserId(id) in one step and retrieve it in another.

IBM

Describe how to use Data Tables in Cucumber and when they are appropriate.

Data Tables let you pass structured data from Gherkin to step definitions as a List<Map<String,String>> or a custom POJO. They are ideal for scenarios requiring multiple input rows, such as creating several users or verifying table contents. In the step definition, Cucumber automatically converts the table, enabling concise loops or assertions without hard‑coding values. Use them when the scenario’s focus is on data variations rather than a single value.

Shopify

How do you implement parameter types for custom transformations?

Cucumber allows you to define @ParameterType methods that convert raw strings into domain objects. For example, @ParameterType("\d{4}-\d{2}-\d{2}") public LocalDate isoDate(String date) { return LocalDate.parse(date); } This lets steps accept a LocalDate directly, improving readability and type safety. Custom parameter types reduce boilerplate in step definitions and keep conversion logic centralized.

LinkedIn

How can you integrate Cucumber with Selenium for UI testing?

Create step definitions that use Selenium WebDriver to interact with the browser. Initialize the driver in a @Before hook, navigate to pages in Given steps, perform actions in When steps, and assert UI elements in Then steps. Use Page Object Model to encapsulate element locators, keeping step definitions readable. Close the driver in an @After hook to release resources. This combination provides readable BDD scenarios that drive real UI interactions.

Uber

How do you handle dynamic data generation within a Cucumber scenario?

Use Java’s Faker library or custom utility methods inside step definitions to generate random but valid data. Store generated values in a scenario‑scoped context (e.g., a World object) so later steps can reuse them. Ensure the data is deterministic for repeatability when needed, by seeding the random generator. This approach keeps the Gherkin steps readable while providing realistic test inputs.

Spotify

Can you mix Cucumber with other testing frameworks like TestNG? How?

Yes. Cucumber‑JVM provides a TestNG runner that extends AbstractTestNGCucumberTests. Annotate the runner class with @CucumberOptions to specify features, glue, and tags. TestNG then manages the execution lifecycle, allowing you to leverage TestNG’s data providers, listeners, and parallel execution settings alongside Cucumber scenarios. This hybrid approach lets teams reuse existing TestNG infrastructure while adopting BDD.

Cisco

Explain how to use Cucumber Expressions versus Regular Expressions.

Cucumber Expressions provide a simpler, readable syntax for matching step text, using placeholders like {int}, {float}, or {word}. They automatically convert captured values to appropriate types. Regular Expressions offer more flexibility but are harder to read and maintain. Prefer Cucumber Expressions for most cases; switch to regex only when you need complex patterns not covered by built‑in expression types.

Snapchat

What is the role of the World object in Cucumber‑Ruby?

In Cucumber‑Ruby, the World object is the context that step definitions execute within. By extending World with modules or custom methods, you can share state and helper functions across steps. This replaces static variables and provides a clean way to maintain per‑scenario data. Adding methods to World keeps step definitions concise and encourages reuse of common logic.

GitHub

Advanced

What is the purpose of the @ScenarioScope annotation in Cucumber‑Spring?

The @ScenarioScope annotation tells Spring to create a bean instance per scenario, ensuring isolation between runs. This is crucial when tests run in parallel or when mutable state could leak across scenarios. By scoping beans to the scenario lifecycle, you can safely inject services, repositories, or test utilities without risking cross‑contamination, which leads to flaky tests and nondeterministic results.

Oracle

Explain how Cucumber supports parallel execution and what considerations are needed.

Cucumber‑JVM can run scenarios in parallel using the junit-platform‑engine or Maven Surefire with the cucumber‑junit‑parallel plugin. To enable safe parallelism, avoid shared static state, use scenario‑scoped dependency injection, and ensure the underlying WebDriver or API client supports concurrent sessions. Configure the thread count, and consider using a thread‑local driver manager to isolate browser instances. Proper isolation prevents race conditions and improves CI speed.

Apple

How would you debug a flaky Cucumber scenario?

First, reproduce the failure locally with the same data and environment. Add detailed logging or screenshots in @AfterStep hooks to capture state at each step. Examine timing issues, such as implicit waits or asynchronous UI updates, and replace them with explicit waits. Verify that shared resources (e.g., databases) are reset between runs. Finally, isolate the step causing instability and refactor it to be deterministic, possibly by mocking external services.

Twitter

Explain the role of the cucumber‑junit‑platform‑engine in modern test suites.

The cucumber‑junit‑platform‑engine bridges Cucumber with JUnit 5, allowing you to run Cucumber features as JUnit tests. This integration enables use of JUnit’s powerful features such as extensions, parameterized tests, and parallel execution configuration. It also simplifies IDE support, letting developers run individual scenarios with a single click. The engine respects Cucumber’s lifecycle hooks while leveraging JUnit’s reporting and test discovery mechanisms.

PayPal

What is the purpose of the @BeforeAll and @AfterAll hooks in Cucumber‑JVM?

@BeforeAll runs once before any scenario in a test run, useful for expensive setup like starting a Docker container or initializing a database schema. @AfterAll runs after all scenarios, allowing you to clean up shared resources. They differ from @Before/@After, which execute per scenario. Use them sparingly to avoid cross‑scenario contamination, and combine with @ScenarioScope beans for safety.

Dropbox

What are the trade‑offs of using Cucumber for API testing versus unit testing?

Cucumber excels at high‑level acceptance criteria, making API tests readable for non‑technical stakeholders. However, it adds abstraction layers and execution overhead compared to direct unit tests, potentially slowing feedback. Unit tests are faster, more granular, and easier to debug. A balanced strategy uses Cucumber for end‑to‑end API validation while keeping low‑level unit tests for core logic, ensuring both coverage and speed.

Square

How would you handle a scenario where multiple step definitions match the same Gherkin step?

Cucumber throws an AmbiguousStepDefinitionsException, indicating duplicate matches. Resolve it by refining the regular expressions or Cucumber Expressions to be more specific, or by using @Priority (if supported) to indicate precedence. Consolidate similar steps into a shared definition if they perform identical actions. Maintaining unique, descriptive step patterns prevents ambiguity and keeps the step library maintainable.

Pinterest

Describe how to use @BeforeStep and @AfterStep hooks effectively.

@BeforeStep runs before each step, allowing you to set up preconditions like resetting mocks or logging the step name. @AfterStep runs after each step, useful for taking screenshots on failure or capturing API responses. Implement them to add fine‑grained observability without cluttering individual step definitions, thereby keeping steps focused on business intent while still providing detailed diagnostics.

Netflix

Common mistakes

  • Using static variables for shared state, causing cross‑scenario contamination
  • Writing overly complex regular expressions instead of simple Cucumber Expressions
  • Mixing UI and API actions in the same step, breaking readability
  • Neglecting to reset mocks or test data in @After hooks, leading to flaky tests
  • Overusing @BeforeAll for per‑scenario setup, causing hidden dependencies

Study plan

  1. Read the official Cucumber documentation and focus on Gherkin syntax
  2. Implement a small project: write feature files, step definitions, and hooks in Java
  3. Add Data Tables, Scenario Outlines, and custom parameter types to the project
  4. Configure parallel execution and integrate with Selenium for UI testing
  5. Practice debugging flaky scenarios and generating HTML reports

FAQ

Do I need to know Java to use Cucumber?

Cucumber supports many languages, but Java is the most common in enterprise environments. Knowing Java helps you write step definitions, configure Maven/Gradle, and integrate with Selenium. If you work in JavaScript or Python, you can use Cucumber‑JS or Cucumber‑Py similarly.

Can Cucumber be used for unit testing?

While possible, Cucumber is best suited for acceptance and integration tests. Unit tests benefit from faster frameworks like JUnit or pytest. Use Cucumber to validate end‑to‑end behavior and keep unit tests separate for speed and granularity.

How many scenarios should a feature file contain?

Aim for 3–5 scenarios per feature to keep files readable. If a feature grows beyond that, consider splitting it into logical sub‑features or using Scenario Outlines to handle data variations.

What is the recommended way to handle test data setup?

Use @Before hooks combined with scenario‑scoped dependency injection to create fresh data for each scenario. Leverage factories or builders to generate objects, and clean up in @After hooks to maintain isolation.

Is it okay to commit step definition files to version control?

Yes, step definitions are code and should be versioned alongside the application. Keep them in the same repository as the feature files to ensure traceability and simplify CI integration.

Related

Ready for your next interview?

Download MiPrep AI. Load your resume and the job description. Show up ready.

Free tier · No credit card · macOS 14+ · Windows 10+

Free tier · No credit card · Runs on your Mac or Windows machine