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

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.

Example:

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).

Conclusion:

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”]

 
Share:

Related Posts

Navigating Big Data Storage Challenges

Navigating Big Data Storage Challenges

The last decade or so has seen a big leap in technological advancements. One of the technologies to come up at this time and see a rapid…

Share:

A Deep Dive into 5G Service-Based Architecture (SBA)

5G technology roll out signifies an immense revenue opportunity for telecom industry.

Share:
Technical Documentation

Technical Documentation Review and Tips

Technical reviews are vital for effective and quality documentation. To make this happen, have documentation and its reviews listed as one of the deliverables – just like development or testing. This will place priority on the process, and ensure everyone involved understands the importance of proper and thorough reviews.

Share:
Generative AI and the changing face of Software Development Lifecycle

Generative AI and the changing face of Software Development Lifecycle

Generative AI is revolutionizing many IT segments, and one of such segments is software product development lifecycle (SDLC). This blog summarizes how Generative AI is transforming SDLC with its applications, benefits, and examples.

Share:
DevOps Revolution

DevOps Revolution: Future Market Trends and Adoption Strategies

The DevOps revolution take in a transformative landscape of software development and IT operations, paving the way for a seamless and collaborative approach to the entire product development lifecycle. DevOps practices involve transformative trends and adoption strategies to enable enterprises to realize agility, reliability, and flexibility in delivering software. Automation, Continuous Integration, and Continuous Delivery (CI/CD) pipelines are becoming recognizable, guaranteeing faster releases and reduced Time-To-Market (TTM). Read the blog to explore the bright future of DevOps in the software industry, and the emerging DevOps trends in 2024.

Share:
Technology Trends 2024

Technology Trends 2024- The CXO perspective

In the rapidly evolving landscape of 2024, technology trends are reshaping industries and redefining business strategies. From the C-suite perspective, executives are navigating a dynamic environment where artificial intelligence, augmented reality, and blockchain are not just buzzwords but integral components of transformative business models. The Chief Experience Officers (CXOs) are at the forefront, leveraging cutting-edge technologies to enhance customer experiences, streamline operations, and drive innovation. This blog delves into the strategic insights and perspectives of CXOs as they navigate the ever-changing tech terrain, exploring how these leaders are shaping the future of their organizations in the era of 2024’s technological evolution.

Share:

This Post Has One Comment

Comments are closed.