How We Used Maven and Cucumber to Automate Regression Testing
- May 1
- 2 min read
In today’s fast-paced development environment, regression testing is essential to ensure that new changes don’t break existing features. Our team faced challenges with manual regression tests taking too long and missing edge cases. That’s when we decided to automate our regression suite using Maven and Cucumber—a powerful combination for Behavior-Driven Development (BDD) in Java.
Here’s a look at our journey and how we made it work.
Why We Chose Maven and Cucumber
Cucumber allowed us to write test scenarios in plain English using Gherkin syntax, making collaboration across the team easier. Maven helped us manage dependencies and run tests efficiently while integrating well into CI/CD pipelines.

Project Setup Overview
/src
/main/java
/test/java
/stepdefinitions
/runners
/features
pom.xml
Key Dependencies in pom.xml:
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.11.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Writing Our Test Scenarios
Feature: Login Functionality
Scenario: Successful login with valid credentials
Given the user is on the login page
When the user enters valid username and password
Then the user should be redirected to the dashboard
Step definition example:
@Given("the user is on the login page")
public void user_on_login_page() {
driver.get("https://example.com/login");
}
Running the Tests with Maven
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/java/features",
glue = "stepdefinitions",
plugin = {"pretty", "html:target/cucumber-report.html"},
tags = "@Regression"
)
public class TestRunner {}
To execute:
mvn test
Reporting
Maven’s Surefire plugin and Cucumber’s built-in report generation helped us produce clean HTML reports, which we shared with the team for every build.
CI/CD Integration
We added our Maven commands to Jenkins, enabling automated test execution on every code push. This ensured that regression bugs were caught early in the release cycle.
Lessons Learned
Keeping Gherkin scenarios simple and focused improved readability.
Tagging scenarios (@Regression,@Smoke,@Sanity) made test execution flexible.
Regular refactoring of step definitions helped avoid duplication and improved maintainability.
Final Thoughts
Automating regression tests with Maven and Cucumber streamlined our QA process, improved collaboration, and gave us faster feedback on code changes. If your team is looking for a maintainable way to scale test automation, this combination is a great place to start.
At BusyQA, we offer courses designed to equip you with the skills necessary to become a proficient Automation Test Engineer by 2025. Our Curriculum is both felxible and accessible, complemented by an co-op program that has successfully intiated the careers of numerous Automation and Software Testing Engineers.
댓글