top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

Let’s understand BDD with Cucumber


BDD for all!


Let’s dive into understanding what BDD (Behavior Driven Development) is, how is it used and how it helps with communication between different stakeholders.

In current Software Development world, we have various stakeholders each with their own interest. In general, we can divide the stakeholders into 2 groups -

1.Internal stakeholders include business owners, managers, and employees, who are directly involved with product development.

2. External stakeholders are entities such as clients, investors, suppliers, etc.

Each stakeholder group has its own vocabulary that they use in their day to day operations which could often leads to confusion of what actually needs to be done .

In order to have a formal and verifiable way of checking that the business needs align with the actual application features, the Software Engineers, QA analysts and Engineering/Product Managers work together and create user stories.

Did you know : A user story is a very high-level definition of a requirement, containing just enough information so that the developers can produce a reasonable estimate of the effort to implement it and test it.

A good user story should capture the expected behavior which is the test outcome of the functionality being tested , as we know fixing a bug in production is costlier than fixing in development or testing phase , Software Testing has its own niche place in Software product development.

Before taking a deep dive into how BDD helps bridging the communication gap and how user stories gets translated into something more tangible that becomes part of your test modules , lets check some basics of Software Testing.

How to test a software ? Well, there are various approaches to testing. Let’s describe some of them.

  1. Test-first approach, where you write tests first and then drive your code by making the tests pass. One application of this is Test Driven Development or TDD

  2. Test-last approach, where you write code first and then you write tests to verify that. You might have been writing code like that until now.



Problems with TDD

  • When to test?

  • What to test?

  • How to know if a specification is met?

  • Does the code deliver business value?


Even Drake recommends BDD


Overcoming those disadvantages is why BDD was born. But what exactly is BDD?


 

What is BDD?

BDD (Behavior Driven Development) is a technique where you define your specifications or test cases using simple English-like sentences in Gherkin language. With this technique, the non-technical team members can easily understand the flow and collaborate with other team members in the process of software development.

 

Why BDD framework?

  • BDD scenarios are written in plain English, which is easy to understand by everyone involved in the project, from stakeholders to project team members.

  • Scenarios are written specifically to each functionality which gives clarity for product development and testing.

  • Be it manual or automated, testing becomes very easy as the test cases or the test scripts can be easily identified from the feature files.

  • The maintenance of the framework is simple.

  • BDD also acts as project documentation for all modules and functionalities.

 

Did you know: Cucumber is a great tool used to run acceptance tests using the plain-text functional descriptions using BDD approach?


What is Cucumber?

Cucumber is a behavior-driven development (BDD) testing tool whose goal is to bring together a variety of project responsibilities, such as quality assurance, developers, and business analysts, to understand the application without diving too deeply into the technical components.


 

Why Cucumber?

  • Cucumber supports a variety of programming languages, including Java , .net and Ruby.

  • It serves as a link between commercial and technical language. This can be done by writing a test case in plain English text.

  • It enables the test script to be developed without any prior knowledge of programming, as well as the participation of non-programmers.

  • Unlike other tools, it functions as an end-to-end test framework.

  • Cucumber allows for code reuse thanks to its simple test script architecture.

 

Can’t wait to get started with Cucumber? To help you out, we will be diving into some of the best Cucumber practices that will enable you to write better scenarios using the Gherkin language. You will also get a clearer picture of the behavior driven development concepts with these practices.

Before going into further let get a quick overview on gherkins language.

What is Gherkin ?

Gherkin is a readable business language that allows you to define business activity without getting deep into 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 elements from behavior testing.


 

Some Basics concepts in Cucumber BDD Framework

There are a few things you need to understand about the Cucumber BDD framework. To work with cucumber using selenium automation testing, you would need three types of files as described below:

  • Feature File — It serves as an entry point to the Cucumber tests. It is the file where your test scenarios are written in Gherkin language. A Feature file may contain single or multiple test scenarios. The Feature file is used as a live document and ends with .feature extension.


Feature file


  • Step Definition — It contains the piece of code, in your chosen programming language, with some annotations attached to it. On seeing a Gherkin Step, Cucumber executes the code which is contained within the Step. The annotation has a pattern that links the Step Definition to the matching steps defined in the Feature File.


Step Definition File

  • Others — We may need other files to execute tests at different levels. For example, we are testing the Web UI; then, we will be using a tool like Selenium, which might use a framework of its own like the Page object model. Since in this post, our primary focus is Cucumber best practices, let us leave the other files’ detailing for some other time.


 

What are some alternatives Cucumber?

Spec Flow : Spec flow is a Behavior data-driven (BDD) automation framework. In simple words “Spec flow is cucumber of .NET”. Junit : JUnit is a unit testing framework for the Java programming language. Behave : A Python library to implement BDD tests. It is behavior-driven development, Python style. It uses tests written in a natural language style, backed up by Python code. JBehave : JBehave is a tool for implementing Behavior Driven Development (BDD) in Java. Lettuce : Behavior-driven-development tool for python, inspired by Cucumber for Ruby. Kahlan : Kahlan is a full-featured Unit & BDD test framework a la RSpec/JSpec which uses a describe it syntax and moves testing in PHP one step forward. Jasmine : Jasmine is an open-source JavaScript framework, capable of testing any kind of JavaScript application. Spock : Spock is a BDD-style developer testing and specification framework for Java and Groovy applications. Yadda : Yadda brings true BDD to JavaScript test frameworks.

Summing up

In this article, I have given an overview of BDD framework with cucumber. In next article we will implement the cucumber BDD framework using selenium and will integrate it with Maven project.

Happy Testing!


22 views0 comments

+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2022 by NumPy Ninja

  • Twitter
  • LinkedIn
bottom of page