Prev Next

Testing / Cucumber Interview Questions

1. What is the Cucumber framework? 2. What is Cucumber? 3. What is Gherkin Language? 4. What is Behavior-Driven Development (BDD)? 5. What is Gherkin? 6. Mention a few of the keywords in Cucumber. 7. Which language is used in Cucumber? 8. What is a Cucumber feature file? 9. What is a step definition in Cucumber? 10. What are the files required in Cucumber Framework? 11. What is glue code in Cucumber? 12. What is the purpose of Given, When, Then in Cucumber scenarios? 13. What is a Background section in a Cucumber feature file? 14. What is a Scenario Outline in Cucumber? 15. What is an Examples table in Cucumber? 16. What are Cucumber Expressions? 17. What are hooks in Cucumber? 18. What is a Data Table in Cucumber? 19. What is a Doc String in Cucumber? 20. What are tags in Cucumber? 21. What is the Cucumber Runner in Java? 22. What is Dependency Injection used for in Cucumber? 23. What is the World object in Cucumber? 24. What is a Cucumber HTML report? 25. What are the main components of the Cucumber ecosystem? 26. What is SpecFlow/Reqnroll, and how does it relate to Cucumber? 27. What is a Pickle in Cucumber's internal architecture? 28. What is Cucumber Pro/Cucumber Studio? 29. What is the three amigos concept in BDD? 30. What is living documentation in the context of Cucumber? 31. Explain the execution flow of a Cucumber scenario from feature file to step definition? 32. Why does Cucumber require step definitions while Karate doesn't? 33. How does Cucumber differ from Karate for API/BDD testing? 34. What is the difference between @Before and @BeforeStep hooks? 35. How do you implement data-driven testing using Scenario Outline and Examples in Cucumber? 36. When should you use regex-based step definitions versus Cucumber Expressions? 37. How do you troubleshoot an "Undefined step" error in Cucumber? 38. What is the difference between Cucumber Expressions and regular expressions for step matching? 39. How does Cucumber-JVM handle parallel test execution with the JUnit 5 Platform Suite? 40. Explain the internal working of Cucumber's Pickle compilation process? 41. What is the difference between Cucumber and TestNG/JUnit as testing tools? 42. How do you implement dependency injection across step definition classes using PicoContainer or Spring? 43. Why use tag expressions instead of simple tag matching for selective test execution? 44. What is the difference between a Data Table and a Doc String in Cucumber? 45. How does Cucumber handle transforming Data Tables into Java objects? 46. When would you choose SpecFlow/Reqnroll over Cucumber-JVM for a.NET project? 47. How do you configure the Cucumber JUnit 5 Platform Suite runner? 48. What is the difference between imperative and declarative Gherkin style? 49. Explain the lifecycle of hooks around a scenario's execution? 50. How do you optimize a large Cucumber regression suite for faster execution? 51. What is the difference between global hooks and tagged (conditional) hooks? 52. How does Cucumber's step definition matching resolve ambiguous step matches? 53. Why should step definitions avoid containing assertions tightly coupled to UI selectors? 54. What is the difference between Scenario and Rule in Cucumber's Gherkin? 55. How do you troubleshoot flaky Cucumber scenarios caused by shared mutable state across step definition classes?

1. What is the Cucumber framework?

Cucumber is a behavior-driven development (BDD) testing tool. It provides a method for writing tests that anyone, regardless of technical knowledge, can comprehend. We can write test scripts from both the developer's and the customer's perspectives with Behavior Driven Development.

Read full answer

2. What is Cucumber?

Cucumber is an open-source test automation tool that supports Behavior-Driven Development (BDD) by letting teams write executable specifications in plain, structured language, using a format called Gherkin, and running those specifications directly as automated tests. Originally written in Ruby b...

Read full answer

3. What is Gherkin Language?

Gherkin is a readable business language that allows you to define business activity without getting bogged down in implementation specifics. It's a domain-specific language for defining specs tests in Cucumber format. It describes use cases in plain English and helps users to remove logic element...

Read full answer

4. What is Behavior-Driven Development (BDD)?

Behavior-Driven Development is a collaborative software development approach where requirements are captured as concrete examples of system behavior, written in plain language that both technical and non-technical stakeholders can read and agree on, before any code is written. Rather than startin...

Read full answer

5. What is Gherkin?

Gherkin is the plain-text, line-oriented language Cucumber (and its Gherkin-compatible relatives, like SpecFlow/Reqnroll) uses to describe behavior in a structured but human-readable way. It uses a small, fixed set of keywords, Feature , Scenario , Given , When , Then , And , But , and a few othe...

Read full answer

6. Mention a few of the keywords in Cucumber.

Feature collects relevant scenarios and provides a high-level description of a software feature. Rule is used to express a single business rule that should be followed. It adds to the information about a feature. Example is a practical illustration of a business rule. It comprises a series of ste...

Read full answer

7. Which language is used in Cucumber?

Cucumber tool was originally written in the "Ruby" programming language. It was exclusively used only for testing Ruby as a complement to the RSpec BDD framework. But now, Cucumber supports a variety of different programming languages including Java, JavaScript, PHP, Net, Python, Perl, etc. with ...

Read full answer

8. What is a Cucumber feature file?

A feature file is a plain-text file with a .feature extension containing one Feature and one or more Scenario s written in Gherkin, describing the expected behavior of a piece of functionality from the perspective of someone using it. Feature: user login Scenario: successful login with valid cred...

Read full answer

9. What is a step definition in Cucumber?

A step definition is a piece of code, in whichever language the Cucumber implementation targets (Java, Ruby, JavaScript, and so on), that implements the actual behavior for a specific Gherkin step by matching that step's text to a pattern. @Given ( "a registered user {string} with password {strin...

Read full answer

10. What are the files required in Cucumber Framework?

Feature File has plain text descriptions of single or numerous test situations. Keywords like Then, When, Background, Scenario Outline, Feature, And, But, and so on are used in the tests. As a result, it's a file that keeps track of features and their descriptions. Step Definition File (.java fil...

Read full answer

11. What is glue code in Cucumber?

"Glue" is Cucumber's own term for the code that connects, or "glues", Gherkin steps to their executable implementations: step definitions and hooks together. The term shows up directly in configuration, such as the glue path setting that tells Cucumber which package to scan for this code. @Suite ...

Read full answer

12. What is the purpose of Given, When, Then in Cucumber scenarios?

Given , When , and Then structure a scenario into three conceptual parts: establishing context, performing an action, and observing an outcome. And and But continue whichever of the three sections precedes them, avoiding repetitive keyword use for multiple steps in the same category. Scenario: wi...

Read full answer

13. What is a Background section in a Cucumber feature file?

A Background section contains steps that run before every scenario in a feature file, used to factor out setup steps that would otherwise be repeated identically at the top of each scenario. Feature: order management Background: Given the catalog contains a product "Widget" priced at 9.99 And a c...

Read full answer

14. What is a Scenario Outline in Cucumber?

A Scenario Outline defines a single scenario template containing placeholders, then runs it once for each row of a paired Examples table, avoiding the need to write nearly identical scenarios by hand for each combination of inputs. Scenario Outline: login attempts with different credentials Given...

Read full answer

15. What is an Examples table in Cucumber?

An Examples table supplies the concrete data values a Scenario Outline is run against, with each column header matching a placeholder name used in the outline's steps, and each subsequent row producing one independent execution of that outline. Examples: | item | quantity | expectedTotal | | Widg...

Read full answer

16. What are Cucumber Expressions?

Cucumber Expressions are a simpler, more readable alternative to regular expressions for matching step text and extracting parameters, using a small set of built-in parameter types like {string} , {int} , and {word} instead of regex syntax. // Cucumber Expression @Given ( "a registered user {stri...

Read full answer

17. What are hooks in Cucumber?

Hooks are blocks of code that run at defined points around a scenario's execution, independent of any specific Gherkin step, used for cross-cutting setup and teardown concerns like opening a browser, starting a database transaction, or capturing a screenshot on failure. @Before public void setUp(...

Read full answer

18. What is a Data Table in Cucumber?

A Data Table is a pipe-delimited table attached directly beneath a Gherkin step, letting that single step carry structured, tabular data as an argument, rather than needing one step per row of data. Given the following users exist: | username | role | active | | alice | admin | true | | bob | use...

Read full answer

19. What is a Doc String in Cucumber?

A Doc String is a multi-line piece of text attached to a Gherkin step, delimited by triple quotes, used when a step needs to pass a larger block of text, like a JSON payload, an email body, or a chunk of expected output, that wouldn't read well crammed onto a single line. Whe n t he clie nt submi...

Read full answer

20. What are tags in Cucumber?

Tags are @ -prefixed labels placed above a Feature , Scenario , or Examples block, used to categorize scenarios so a test run can be filtered to include or exclude specific groups without physically separating files. @smoke Scenario: basic health check Given the service is running When a health c...

Read full answer

21. What is the Cucumber Runner in Java?

The runner is the entry point that tells the build tool (Maven, Gradle) and test framework (JUnit) how to discover and execute Cucumber scenarios. The current recommended approach in Cucumber-JVM uses the JUnit 5 Platform Suite engine rather than the older JUnit 4-style @RunWith(Cucumber.class) r...

Read full answer

22. What is Dependency Injection used for in Cucumber?

Cucumber creates a fresh instance of every step definition class for each scenario, which means step definition methods spread across multiple classes (for readability and organization) can't simply share state through instance fields the way methods within a single class normally could. Dependen...

Read full answer

23. What is the World object in Cucumber?

In Cucumber's Ruby and JavaScript implementations, the "World" is a fresh object created for each scenario that step definitions execute within, serving the same role Java's dependency-injected shared context objects serve: a place to store and share state across steps within one scenario, withou...

Read full answer

24. What is a Cucumber HTML report?

Cucumber can generate a self-contained HTML report summarizing a test run: which scenarios passed or failed, the specific step that caused a failure, execution timing, and any attached evidence like screenshots, configured via the cucumber.plugin setting. @ConfigurationParameter ( key = "cucumber...

Read full answer

25. What are the main components of the Cucumber ecosystem?

A working Cucumber setup is made up of a handful of distinct pieces that work together, each with a specific responsibility. Gherkin - the parser and grammar defining the plain-language syntax feature files are written in. Feature files - the .feature files containing scenarios written in Gherkin...

Read full answer

26. What is SpecFlow/Reqnroll, and how does it relate to Cucumber?

SpecFlow (now continued under the community-driven fork Reqnroll, after SpecFlow's commercial development wound down) is a BDD framework for .NET that uses the same Gherkin syntax and feature-file format as Cucumber, but with its own separate implementation, test runner integration, and step-defi...

Read full answer

27. What is a Pickle in Cucumber's internal architecture?

A "Pickle" is Cucumber's internal, language-agnostic representation of a single, concrete, executable scenario, produced by compiling a Gherkin document (resolving Background steps, expanding Scenario Outline / Examples combinations, and so on) into a flat, self-contained structure that's easier ...

Read full answer

28. What is Cucumber Pro/Cucumber Studio?

Beyond the free, open-source Cucumber engine that actually executes tests, SmartBear (Cucumber's commercial steward) offers Cucumber Studio (previously known by other names across its history, including Cucumber Pro and, before that, HipTest), a hosted, collaborative platform for authoring and ma...

Read full answer

29. What is the three amigos concept in BDD?

"Three amigos" refers to a collaborative meeting practice, common in BDD adoption, where a business representative (or product owner), a tester, and a developer sit down together before development begins to discuss and refine a feature's requirements into concrete Gherkin examples. The idea is t...

Read full answer

30. What is living documentation in the context of Cucumber?

Living documentation refers to documentation that stays automatically accurate over time because it's the same artifact that's actually executed as a test, rather than a separate written description that has to be manually kept in sync with a codebase as it evolves. A Cucumber feature file is a n...

Read full answer

31. Explain the execution flow of a Cucumber scenario from feature file to step definition?

Running a Cucumber suite involves several distinct phases: discovering feature files, compiling them into executable pickles, and then matching and invoking the right code for each step of each pickle. sequenceDiagram participant Runner as JUnit Platform Suite participant Cucumber as Cucumber Eng...

Read full answer

32. Why does Cucumber require step definitions while Karate doesn't?

Cucumber is a general-purpose BDD engine: it makes no assumptions about what domain a scenario is testing, an API, a UI, a batch job, a piece of business logic entirely unrelated to HTTP, so it has no built-in vocabulary for any of them. Every single step, however common, has to be explicitly imp...

Read full answer

33. How does Cucumber differ from Karate for API/BDD testing?

Both use Gherkin-style syntax, but they diverge sharply in scope and in how much custom code a given test actually requires. Cucumber Karate General-purpose BDD framework for any domain. Purpose-built specifically for API, UI, and mock testing. Every step needs a corresponding step definition. Sh...

Read full answer

34. What is the difference between @Before and @BeforeStep hooks?

@Before runs exactly once per scenario, immediately before its first step executes. @BeforeStep runs once before every individual step within that scenario, meaning it fires multiple times per scenario, once for each step in sequence. @Before @BeforeStep Runs once per scenario. Runs once before e...

Read full answer

35. How do you implement data-driven testing using Scenario Outline and Examples in Cucumber?

Data-driven testing in Cucumber centers on pairing a Scenario Outline , containing angle-bracket placeholders, with an Examples table supplying the concrete values for each run. Scenario Outline: discount calculation by customer tier Given a customer with tier "" And a cart total of

Read full answer

36. When should you use regex-based step definitions versus Cucumber Expressions?

Cucumber Expressions cover the vast majority of everyday step-matching needs, string, number, and word parameters, with substantially more readable syntax than an equivalent regular expression, and should be the default choice for new step definitions. Regular expressions remain the better (or on...

Read full answer

37. How do you troubleshoot an "Undefined step" error in Cucumber?

An "undefined step" error means Cucumber couldn't find any step definition whose pattern matches a given Gherkin line's text, and it's one of the most common early friction points when writing or modifying feature files. Check the glue configuration - confirm the runner's cucumber.glue setting ac...

Read full answer

38. What is the difference between Cucumber Expressions and regular expressions for step matching?

Both ultimately serve the same purpose, matching a step's text and extracting parameters, but they differ substantially in syntax and in what's easy versus hard to express. Cucumber Expressions Regular expressions Readable syntax using named types like {string}, {int}. Symbol-heavy syntax (parent...

Read full answer

39. How does Cucumber-JVM handle parallel test execution with the JUnit 5 Platform Suite?

The JUnit 5 Platform Suite engine, the current recommended way to run Cucumber-JVM, integrates with JUnit Platform's own parallel execution support, letting scenarios run concurrently rather than strictly one after another. # junit-platform.properties cucumber.execution.parallel.enabled=true cucu...

Read full answer

40. Explain the internal working of Cucumber's Pickle compilation process?

Before any test actually executes, Cucumber transforms the raw, human-authored Gherkin in a feature file into a flat set of independently executable Pickles, resolving everything that requires cross-referencing other parts of the file. flowchart TD A[Parse .feature file into an AST] --> B[Identif...

Read full answer

41. What is the difference between Cucumber and TestNG/JUnit as testing tools?

TestNG and JUnit are general-purpose Java test frameworks: tests are written directly as annotated Java methods, with assertions and test logic living entirely in code. Cucumber isn't a competing alternative to them so much as a layer that sits on top of one of them, using JUnit (or TestNG) as th...

Read full answer

42. How do you implement dependency injection across step definition classes using PicoContainer or Spring?

PicoContainer, Cucumber-JVM's zero-configuration default DI option, automatically detects step definition classes with a single constructor and wires up shared instances of any classes referenced across multiple step definition classes, with no explicit registration required. public class SharedC...

Read full answer

43. Why use tag expressions instead of simple tag matching for selective test execution?

Early Cucumber versions supported only simple, comma/space-separated tag lists with limited combining logic. Modern tag expressions support full boolean logic, and , or , not , and parentheses for grouping, which lets a single run target precisely the intersection of tags actually needed. # Run s...

Read full answer

44. What is the difference between a Data Table and a Doc String in Cucumber?

Both let a single Gherkin step carry a larger chunk of structured data as an argument, but they're suited to different shapes of data: a Data Table for genuinely tabular, row-and-column data, and a Doc String for a single block of free-form text. Data Table Doc String Pipe-delimited rows and colu...

Read full answer

45. How does Cucumber handle transforming Data Tables into Java objects?

Beyond the built-in conversions ( asMaps() , asLists() , asMap() for two-column tables), Cucumber-JVM lets a project register custom transformers so a Data Table converts directly into a list of domain objects, avoiding repetitive manual field-by-field parsing inside every step definition that co...

Read full answer

46. When would you choose SpecFlow/Reqnroll over Cucumber-JVM for a.NET project?

Cucumber-JVM specifically targets the JVM; running it directly isn't a natural fit for a codebase built on .NET, since the step definitions would need to be written in a JVM language and the test execution wouldn't integrate cleanly with .NET's own build and test tooling (MSBuild, dotnet test, Vi...

Read full answer

47. How do you configure the Cucumber JUnit 5 Platform Suite runner?

Configuring the JUnit 5 Platform Suite for Cucumber-JVM involves a small set of annotations on an otherwise-empty class, plus configuration parameters controlling glue location, formatters, and filtering. import org.junit.platform.suite.api. * ; @Suite @IncludeEngines ( "cucumber" ) @SelectClassp...

Read full answer

48. What is the difference between imperative and declarative Gherkin style?

Imperative-style scenarios spell out every low-level UI or API interaction step by step, closely mirroring exactly how a user would click through a workflow. Declarative-style scenarios instead describe the outcome or intent in business terms, leaving the low-level mechanics to be handled inside ...

Read full answer

49. Explain the lifecycle of hooks around a scenario's execution?

Cucumber runs several distinct categories of hooks at different points relative to a scenario and its individual steps, and understanding the exact ordering matters for reasoning about setup, teardown, and diagnostic capture correctly. flowchart TD A[Scenario selected to run] --> B[Run all applic...

Read full answer

50. How do you optimize a large Cucumber regression suite for faster execution?

As a Cucumber suite grows into the hundreds or thousands of scenarios, runtime becomes dominated by a handful of specific factors, most of which have direct, well-established mitigations. Enable and tune parallel execution - configure the JUnit 5 Platform Suite's parallel execution properties and...

Read full answer

51. What is the difference between global hooks and tagged (conditional) hooks?

A hook with no tag expression applies unconditionally to every single scenario in the suite. A tagged hook only runs for scenarios matching its associated tag expression, letting different categories of scenarios receive different setup or teardown behavior without every hook needing to apply uni...

Read full answer

52. How does Cucumber's step definition matching resolve ambiguous step matches?

When a step's text matches more than one registered step definition's pattern, Cucumber doesn't guess or silently pick one; it fails the step with an explicit "ambiguous step definitions" error, listing every matching candidate, since silently choosing one could hide a real bug where two step def...

Read full answer

53. Why should step definitions avoid containing assertions tightly coupled to UI selectors?

A step definition that hardcodes specific UI selectors (like a CSS class or XPath) directly alongside its assertion logic becomes fragile in two compounding ways: any change to the UI's markup breaks the step definition, and because the same step definition is often reused across many scenarios, ...

Read full answer

54. What is the difference between Scenario and Rule in Cucumber's Gherkin?

Scenario is the standard, most commonly used container for a single test case. Rule is a newer Gherkin keyword that groups multiple related scenarios together under a single business rule being illustrated, giving that group its own optional Background distinct from the feature-level one. Feature...

Read full answer

55. How do you troubleshoot flaky Cucumber scenarios caused by shared mutable state across step definition classes?

Flakiness that appears only sometimes, especially under parallel execution, and often involves one scenario's data or assumptions unexpectedly showing up in an unrelated scenario, is a strong signal of shared mutable state leaking across what should be isolated scenario executions. Check for stat...

Read full answer

«
»

Comments & Discussions