Behavior-Driven Development (BDD) Test Automation Using Cucumber

What is BDD

Behavior-driven development (BDD) is a software development process that has come out of the software engineering methodology of test-driven development (TDD).

BDD (behavior-driven development) is largely facilitated through the use of a simple domain-specific language (DSL) using natural language constructs (e.g., English-like sentences) that can express behavior and expected outcomes. Test scripts have long been a popular application of DSLs with varying degrees of sophistication. Behavior-driven development is considered as an effective technical practice especially when “problem space” of the business problem to solve is complex.


Gherkin is the language which Cucumber understands. It is the Business Readable, Domain Specific Language that lets you describe software’s behavior without detailing how that behavior is implemented.

Behavior-Driven development (BDD) using Cumumber

Cucumber Introduction:

Cucumber is a tool based on Behavior Driven Development (BDD) framework which is used to write acceptance tests for web application.People like Business Analysts, Developers, Testers, etc. Can use this tool for automation of functional validation in easily readable and understandable format (like plain English).

Cucumber feature files can serve as a good document for all. There are other tools also, like JBehave which also support BDD framework. Initially Cucumber was implemented in Ruby and then extended to Java framework. Both tools support native JUnit.

Behavior Driven Development is extension of Test Driven Development and it is used to test the system rather than testing the particular piece of code.

Cucumber Basics:

For the better understanding of cucumber we need to know all the features of cucumber and its usage.

1) Feature Files:

Feature files are essential part of cucumber which is used to write the automation steps for tests or acceptance tests. This can be used as live document. The steps are the application specification. All the feature files ends with .feature extension.

2) Feature:

This let user to know more about the information for the high level business functionality (Refer to previous example) and the purpose of Application under test.By reading the first Feature step everybody should be able to understand the intent of feature file.

3) Scenario:

Basically a scenario represents a particular functionality which is under test. Scenario should be written in such a way that by seeing it the user should be able to understand the intent behind it and what the test is all about. Each scenario should follow or should be in “gherkin” language which is nothing but in given, when and then format.

  1. Given: Given specifies the pre-conditions. It is basically a known state.
  2. When: When specifies the action to be performed. As in below example when the user tries to log in using username and password, it becomes an action.
  3. Then: Then specifies the expected outcome or the result of the action performed. For Instance: Successfull login is the expected outcome or the result after providing USERNAME and PASSWORD.
  4. Background: Background specifies the step that needs to be performed in each scenario. For Instance: If user needs to clear database before each scenario then those steps can be put in background.
  5. And: And is used to combine two or more same type of action.


Feature: Login Functionality Feature
Scenario: Login Functionality
Given user navigates to SOFTWARETETINGHELP.COM
When user provides Username as “USER”
And password as “password”
Then the user should be able to successfully login
And The user get redirected to the Home page

4) Scenario Outline:

Scenario outlines are used when same test has to be performed with different data set.

5) Tags:

Cucumber by default runs all scenarios in all the feature files. In real time projects there could be hundreds of feature file which are not required to run at all times.

For instance: Feature files related to regression test need not run all the time. So if you mention a tag as regressionTest in each feature file which is related to smoke test and run cucumber test with @RegressionTest tag . Cucumber will run only those feature files specific to given tags.

6) Junit Runner:

To run the specific feature file cucumber uses standard Junit Runner and specify tags in @Cucumber. Options. Multiple tags can be provided by using comma separate. Here you can specify the path of the report and type of report you want to generate.

Implementation of Feature file:

We have to implement these steps in Java in order to test the feature files. Need to create a class which contains those given, when and then statements. Cucumber uses its annotations and all the steps are embedded in those annotations (given, when, then).Each phrase starts with “^” so that cucumber understands the start of the step. Similarly each step ends with “$”. User can use regular expressions to pass different test data. Regular expressions take data from feature steps and passes to step definitions. The order of parameters depends how they are passed from feature file.

Lets talk about BDD automation framework using Cucumber.

BDD automation framework using Cucumber consists of following structure:

  • Feature File : Main controller of framework is “Feature File” which consist of the test cases.
  • Test case : It should be written in Gherkin format that is “Given , When and then”
  • Implementation : In order to test the feature files we need to implement these steps in Java . Need to create a class which contains those given, when and then statements.

Cucumber uses following annnotations(i.e given, when, then) whose steps are embedded in  annotations itself.

Reports :  Cucumber generates its own html format. However better reporting can be done using Jenkins or bamboo tool(CI tools).


Cucumber is a most favorite tool for many projects as it is easy to understand, readable and contains business functionality.

[Tweet “Behavior-Driven development (#BDD) Test #Automation Using Cucumber  ~ via @CalsoftInc”]


Related Posts

MWC 23 Top Technology Trends

Mobile World Congress (MWC) is the one of the greatest and most influential connectivity events in the mobile industry where mobile device manufacturers, technology providers, and other industry stakeholders come together to showcase their latest products, services, and innovations. MWC 23 was held in Barcelona from 27 February to 2 March 2023. The event highlighted several emerging technologies and latest trends in the industry market. Read the blog to discover the top technology trends at MWC 23 and how these trends grow over the coming years!


Significance of AI to Underpin the Metaverse

The term “Metaverse” generally refers to a hypothetical future version of the internet that would be much more immersive and interactive, resembling a virtual world. Artificial intelligence (AI) is likely to play a major role in the development of the metaverse. AI could be used to create more realistic virtual environments in the future. Explore the blog to understand how can AI shape the Metaverse technology.


The 5G Uprising: Influence on Business and Telco Industry

The impact of 5G on the telecom industry is likely to be substantial and transformative, leading to new growth opportunities, increased efficiency, and improved customer experiences. Explore the blog to understand how 5G will transform business and the telecom industry.


A Guide to Choose the Right Engagement Model for IT Services

Choosing the right IT Services Engagement Model is critical to the success of any business that needs IT support, this blog helps in choosing the suitable engagement model for your business.


Introduction to IT Services Engagement Model

Choosing the right IT services engagement model is important for companies to gain multiple benefits, this blog helps gain introductory information on the engagement models.


Impact of OpenRAN on the Telecom Industry

This interesting read highlights how OpenRAN is changing the telecommunications industry and what this means for the future.


This Post Has One Comment

Leave a comment / Query / Feedback

Your email address will not be published. Required fields are marked *