World’s largest virtual agentic engineering & quality conference
Optimize software development with Cucumber testing. Gain clarity in cucumber language, streamline collaboration, and automate testing for precision.

Veethee Dixit
Author

Himanshu Sheth
Reviewer
Published on: November 20, 2025
Last Updated on: August 11, 2026
Cucumber is a valuable and popular open-source testing framework that facilitates BDD. It serves three primary purposes: automating tests, documenting the software, and facilitating development simultaneously.
TL;DR
Cucumber testing is a behavior-driven development (BDD) approach that uses plain-language Gherkin syntax to define and automate software behavior. By translating human-readable scenarios into automated tests, Cucumber aligns business requirements with technical execution across development, testing, and business teams.
How Cucumber Testing Works
Cucumber is a BDD tool that defines an application's behavior with clear examples before coding. It helps developers understand the desired behavior and eases collaboration with stakeholders.
Cucumber also aids automation testing, offering clear scripts for automation and system acceptance testing.
A Cucumber test needs two files: a feature file that describes behavior in plain-language Gherkin, and step definitions that map each step to code.
Cucumber reads the feature file, matches each step to its definition, runs the code, and reports the result. Because the scenarios are plain language, anyone on the team can read them.
Cucumber testing is widely embraced in software development for behavior-driven development. It brings benefits to developers and stakeholders involved in software projects. Here are some important advantages of using Cucumber testing.
A Cucumber project is organized into three layers, and a test run flows straight through them.
The execution flow runs in order: the test runner starts Cucumber, which reads the feature file, matches each Gherkin step to a step definition, executes the glue code, and reports results as an HTML report.
Feature files never touch code and step definitions never contain business language, which keeps Cucumber readable and maintainable.
Locally, that run loop is limited to one machine and a few browsers. Most teams run their Cucumber suites on a cloud grid instead, so scenarios run across many real browsers and devices in parallel.
TestMu AI is an AI-native test automation platform that runs your Cucumber and Selenium suites in the cloud instead of on local machines. For a BDD suite, that means:
Note: Elevate your Cucumber testing with TestMu AI. Run your BDD suites across 10,000+ browser and OS combinations on the cloud grid. Try TestMu AI Now!
Cucumber was initially built in Ruby with RSpec. It now supports JavaScript, Java, .NET, Python, and more; Java teams can start with Cucumber with Java.
In Cucumber testing, you create feature files with executable test scripts. These executable test scripts are in a language known as Gherkin.
Gherkin is a domain-specific language to compose executable specifications in a readable format. It employs keywords like And, When, Given, Then, and But to articulate the various steps of a test scenario.
Gherkin serves as a plain English text language for interpreting and executing various test scripts.
Test scripts can cover development or business behavior. To address these diverse requirements, testers, product owners, developers, and project managers need to collaborate when writing them.
Since the stakeholders come from different backgrounds, using a common language becomes challenging and poses a risk to the effectiveness of test scripts. Gherkin was developed to mitigate this risk.
Gherkin offers a shared set of keywords in English that is easily understandable by members from various backgrounds, thus ensuring consistent outcomes from test scripts.
Gherkin functions by creating Step Definitions that connect steps and the corresponding code. It also accommodates keywords in different languages, such as French, and step definitions are in various programming languages like JavaScript.
Here's a clear breakdown of the basic structure:
Gherkin scenarios outline how software applications should behave in different situations. To define various parts of a scenario using specific keywords. Here are some primary Gherkin keywords.
Feature: This keyword defines a wide description of the feature or functionality being tested. A Gherkin file typically starts with a Feature definition.
Scenario: A scenario represents a specific test case that portrays a particular function or behavior of the software application. Each Scenario is distinct and has to possess a unique name.
Scenario Outline: This keyword creates a scenario template that can be executed with various data sets called scenario examples.
Examples: Specify different input data sets for a Scenario Outline followed by a table with headers acting as placeholders in the Scenario Outline.
| Role | Username | Password |
| Admin | adminuser | password1 |
| Customer | custuser | password2 |
Given: Describe the initial preconditions or context for the scenario. It sets up a test by defining a system's initial state.
When: Represents an action or event in the scenario. It describes a specific user interaction or a system behavior under examination.
Then: Specify an anticipated outcome or result of the scenario. It outlines an expected behavior or state of the system following the action mentioned in the "When" step.

And: Include additional steps within a scenario, thus ensuring conciseness and readability by preventing repetitive keywords
But: Employed for supplementary steps, especially when the additional step signifies unexpected or adverse outcomes.
These Gherkin keywords establish the foundation for BDD scenarios, thus facilitating the creation of structured and easily comprehensible specifications for all development team members.
Step definitions are the code that implements each step in a scenario. They are written in the language used for the Gherkin steps. The most common languages for Cucumber step definitions are:
Note: Run your Cucumber step definitions against 10,000+ real browser and OS combinations on the TestMu AI cloud grid. Try TestMu AI Now!
Step definitions link human-readable Gherkin scenarios and automation codes that perform the corresponding actions. Here's how they work:
Each Gherkin step (Given, When, Then, And, But) has a matching step definition in your language, so Cucumber can execute and verify the scenario automatically. The keywords themselves are covered in the Gherkin section above.
This example wires up a login test end to end in Java with Maven and JUnit. Start by adding the Cucumber dependencies to your pom.xml:
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.22.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.22.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>Keep all io.cucumber artifacts on the same version. This example uses the JUnit 4 runner (cucumber-junit); on newer projects you can run Cucumber on the JUnit 5 Platform with cucumber-junit-platform-engine instead.
Next, write the scenario in a login.feature file:
Feature: User Login
Scenario: Successful login with valid credentials
Given the user is on the login page
When the user enters a valid username and password
And clicks the login button
Then the user is redirected to the dashboardThen implement the glue code in a LoginSteps.java step definition file:
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;
import static org.junit.Assert.assertTrue;
public class LoginSteps {
@Given("the user is on the login page")
public void user_on_login_page() {
// navigate the WebDriver to the login page
}
@When("the user enters a valid username and password")
public void user_enters_credentials() {
// find the username and password fields and type valid values
}
@When("clicks the login button")
public void clicks_login() {
// click the submit button
}
@Then("the user is redirected to the dashboard")
public void user_on_dashboard() {
assertTrue(true); // assert the dashboard URL or element is present
}
}Finally, create a TestRunner class that ties the feature files to the glue code and runs them:
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/features",
glue = "stepdefinitions",
plugin = {"pretty", "html:target/cucumber-report.html"}
)
public class TestRunner {
}Run it with mvn test. Cucumber reads the feature file, matches each step to its definition, and produces an HTML report. To run it on every push, wire it into Cucumber with Jenkins.
Feature files read like plain English, but the step definitions behind them are still hand-written and hand-maintained. That upkeep is where a BDD suite slows down as it grows.
KaneAI, the GenAI-native testing agent from TestMu AI, closes that gap:
These two comparisons come up constantly, and in both cases the tools solve different problems rather than competing.
Cucumber and Selenium are not alternatives; they work together. Selenium automates the browser, while Cucumber describes the behavior in plain language and organizes the tests around it.
| Aspect | Cucumber | Selenium |
|---|---|---|
| What it is | A BDD framework for readable scenarios | A browser automation library |
| Language layer | Gherkin plus glue code | Direct WebDriver API calls in code |
| Main role | Structure, readability, collaboration | Driving the actual browser |
| Used together? | Yes. Cucumber step definitions call Selenium to act on the UI. | |
TestNG is a test runner and assertion framework; Cucumber is a BDD layer. Cucumber often uses JUnit or TestNG underneath to actually execute its scenarios.
| Aspect | TestNG | Cucumber |
|---|---|---|
| Purpose | A test runner and assertion framework | A BDD layer for behavior-first tests |
| Test style | Annotation-driven Java test methods | Gherkin scenarios mapped to step definitions |
| Best audience | Developers and SDETs | Mixed technical and business stakeholders |
Use Cucumber testing when your team practices BDD, needs acceptance tests, or wants non-technical stakeholders to help write and read Gherkin scenarios for end-to-end and regression testing.
Here are a few situations where Cucumber testing can be particularly beneficial.
BDD projects that use Cucumber still need efficient cross-browser testing, since browser differences directly affect a web application's quality and user experience. Cloud testing platforms like TestMu AI address that need.
Cucumber is one of the most widely used BDD and acceptance testing tools, but it has limitations worth knowing, each with a practical fix. If these become blockers, consider a Cucumber alternative.
Good scenarios are more than a word jumble. Here are the key Cucumber best practices for scenario writing:
Cucumber testing is an efficient approach that promotes collaboration and a shared understanding of application behavior. Plain-language Gherkin specifications bridge communication gaps, streamline testing, and improve software quality.
Teams that adopt Cucumber resolve issues early in the development cycle and ship high-quality software on time. To go deeper or prepare for interviews, review these Cucumber interview questions.
Author
Veethee Dixit is a seasoned content strategist and freelance technical writer specializing in SaaS platforms and AI-driven testing technologies. She has over 8 years of hands-on experience writing SEO focused technical content, simplifying complex topics in software testing, and collaborating with product marketing teams to develop high converting blogs, documentation, whitepapers, and tutorials. She holds a Bachelor of Engineering in Computer Science and has authored 50+ learning hub articles in the software testing domain. Her work has been featured in leading software testing newsletters and cited by top technology publications. Veethee has played a key role in translating complex testing workflows into actionable guides, helping audiences implement automation strategies with clarity and confidence.
Reviewer
Himanshu Sheth is the Director of Marketing (Technical Content) at TestMu AI, with over 8 years of hands-on experience in Selenium, Cypress, and other test automation frameworks. He has authored more than 130 technical blogs for TestMu AI, covering software testing, automation strategy, and CI/CD. At TestMu AI, he leads the technical content efforts across blogs, YouTube, and social media, while closely collaborating with contributors to enhance content quality and product feedback loops. He has done his graduation with a B.E. in Computer Engineering from Mumbai University. Before TestMu AI, Himanshu led engineering teams in embedded software domains at companies like Samsung Research, Motorola, and NXP Semiconductors. He is a core member of DZone and has been a speaker at several unconferences focused on technical writing and software quality.
Did you find this page helpful?
More Related Blogs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance