What Is BDD Testing? Behavior-Driven Development Explained

bdd testing

BDD testing automates behavior-driven development scenarios written in plain Gherkin. Learn how Given-When-Then works, the three amigos, the discovery-formulation-automation process, popular frameworks, and how to run BDD tests in Katalon.

Key takeaways
The 30-second version of this article
BDD testing is the process of automating and executing behavior-driven development scenarios written in a shared business language.
Gherkin structures each scenario with Given, When, and Then statements that technical and non-technical team members can read.
Day-to-day BDD follows 3 steps: discovery, formulation, and automation.
BDD gives the product owner, developer, and tester a common understanding of requirements, but it needs well-prepared requirements and can be less efficient for small teams.
Popular BDD frameworks include Cucumber, SpecFlow, Quantum, and JBehave, and Katalon Studio supports BDD testing with Cucumber.

BDD testing is the practice of automating and executing behavior-driven development scenarios. Teams describe how software should behave in plain Gherkin statements (Given, When, Then) that product owners, developers, and testers can all read, then map each step to code so the scenarios run as automated tests and double as living documentation.

The goal of BDD is to improve collaboration between the technical side and the business side of the organization.

What Is BDD Testing?

BDD (behavior-driven development) is a software development methodology where teams use a shared business language to describe software scenarios. BDD testing is the process of automating and executing these BDD scenarios, so the behavior everyone agreed on is checked every time the tests run.

BDD

BDD testing

What it is

A development methodology

The automation and execution of BDD scenarios

Main output

Scenarios written in a shared business language

Automated tests mapped to those scenarios

Who is involved

Product owner, developer, and tester

Testers and developers who automate the scenarios

A common BDD language is Gherkin. Here's the login scenario written in Gherkin: 

What Is the Gherkin Language?

The Gherkin language is a unique business-readable language used to describe system behaviors and scenarios. It is structured by three primary statements: Given, When, and Then, with each statement describing a specific aspect of the system.

  • The Given statement sets up the initial context for the behavior and defines the starting point of the system.
  • The When statement describes the trigger that brings about a change or behavior in the system.
  • The Then statement defines the expected outcome that should be observed after the event mentioned in the When statement.

After articulating the system behavior in Gherkin, BDD testers turn it into a test script that can be understood by the computer.

Rules in Writing Gherkin Statements

  • Besides Given, When, and Then statements, testers can also use other keywords such as Feature, Rule, Example, And, But, Background, Scenario Outline, Examples to describe the behavior.
  • You should use these keywords at the start of a line.
  • Comments are permitted at the start of a new line and begin with optional spaces, followed by a hash sign (#) and text.
  • Indentation can be achieved using spaces or tabs, with a recommended indentation level of two spaces.

Why Do We Need BDD?

BDD is based on the idea that the three amigos in software development don’t always share the same perspectives. A common ground between them must be established to facilitate smooth communication.

The three amigos include:

  • Product Owner: representing the business side, they simply want to solve a problem they have.
  • Developer: representing the development side, they want to build a solution to solve the problem of the Product Owner.
  • Tester: representing the QA side, they want to know if the solution can actually solve the problem, and what can possibly go wrong with the solution.

The traditional approach to testing does not connect the perspectives of the three amigos:

  • Stakeholders come to the product owner to transfer their requirements
  • The product owner then explains those requirements to developers and testers.
  • Developers then translate the requirements into code, while the testers translate them into test cases.

It was a lengthy process, and loss in translation can occur, which inevitably leads to misunderstandings.

Instead, with BDD, the three amigos come together and have a discussion, then turn the insights into documentation using a shared language to create a common understanding of the issue at hand. Testers can then use a BDD testing framework to create test cases.

Advantages of BDD Testing

With BDD testing, you can:

  • Have a common language for engineers and stakeholders to communicate about user needs and software solutions.
  • Craft user stories and scenarios to define acceptance criteria for specific software features.
  • Promote collaboration among users, quality team, product team, and engineers to achieve consensus on the project's goals.
  • Reduce uncertainties.
  • Enable faster product delivery by the rapid creation of mutually agreed upon automated tests.
  • Reduce errors in software implementation by converting business requirements into a clear format for all executed tests.
  • Minimize the learning curve and jargon.

Limitations of BDD Testing

However, BDD testing is not without limitations:

  • Potentially leads to lengthy stakeholder meetings, since all key stakeholders need to be included in the BDD process.
  • Demands well-prepared software requirements for the Gherkin scripts to accurately express the business needs, which may conflict with the fast-paced nature of Agile teams working from concise specifications.
  • Less efficient for small development teams.

How to Address BDD Challenges

Each limitation of BDD testing has a practical response:

Challenge

How to address it

Lengthy stakeholder meetings

Keep discovery workshops focused on one user story at a time, centered on the product owner, developer, and tester, and timebox them

Requirements that aren't ready for Gherkin

Use discovery to capture rules and open questions next to each example, and only formulate scenarios once those questions are answered

Less efficient for small teams

Apply BDD to the features with the most complex business rules, not to every change

Scenarios that become hard to maintain

Describe behavior, not UI clicks, and reuse step definitions so a single change updates many scenarios

The trade-off is time spent up front on shared understanding in exchange for fewer misunderstandings later. Teams that already struggle with unclear requirements usually see the most value.

The BDD Approach in Testing: 3 Steps

the process of bdd testing

Day-to-day BDD activity follows a 3-step process. These steps help your team make changes to the system with confidence, because the code reflects the documentation, and the documentation reflects everyone's understanding of the problem.

Step

What happens

Output

1. Discovery

Stakeholders meet in discovery workshops to agree on goals and brainstorm concrete examples

User stories, examples, rules, and open questions

2. Formulation

The team converts those discussions into Gherkin feature files

Scenarios that technical and non-technical members can validate before any code is written

3. Automation

Each Gherkin step is mapped to code

Automated tests that run against the system

1. Discovery Stage

During the Discovery stage, stakeholders participate in structured conversations called discovery workshops (also known as brainstorming sessions) where they discuss and reach a mutual agreement on the desired goals.

They start by stating the user story or requirement in a concise format, such as:

After that, they brainstorm examples of how the user story should behave in different scenarios. These examples focus on concrete situations and help to define the expected behavior.

The team then writes each example on sticky notes or a digital tool, arranging them in a structured format. A common format includes:

  • Columns for the example
  • A brief description
  • Rules or constraints
  • Any open questions or areas of uncertainty.

This approach is known as “Example Mapping.” Created by a co-founder of Cucumber, one of the most popular BDD testing frameworks, Example Mapping’s goal is to create a shared understanding of user stories or requirements by breaking them down into smaller, concrete examples for the three amigos to follow.

2. Formulation Stage

The team converts discussions into feature files using Gherkin. These files contain scenarios that define how the system should behave.

This stage ensures that both technical and non-technical team members can read and validate the expected behavior before writing any code.

Below are the detailed Gherkin statements to describe the business scenario of “As a customer, I want to be able to place an online order for products and receive real-time updates on the status of my order”

3. Automation Stage

Finally, the written Gherkin scenarios are turned into automated tests. Each step in a scenario is mapped to its corresponding code section, often called a step definition. A BDD framework such as Cucumber, SpecFlow, or JBehave reads the feature file, matches each Given, When, and Then line to its step definition, and runs the code.

To get the most from this stage:

  • Reuse steps. Write step definitions so the same line, such as "Given the user is on the login page", works across many scenarios.
  • Run scenarios in your CI pipeline. Running BDD tests on every change shows which agreed behavior broke, written in the same language the team used to define it.
  • Refine through iteration. When a scenario fails because the requirement changed, update the feature file first, then the code. That keeps the scenarios accurate as living documentation.

Steps To Do BDD in TDD

BDD Operation

Test-driven development (TDD) is an iterative process where code quality is guided and continuously improved through tests. The process of TDD is:

  1. Define behavior with BDD using Gherkin (Given, When, And, Then).
  2. Write tests (even before writing code). The idea is to run these tests and watch them fail. After that, we write code until the tests pass, essentially using the tests to drive the development process.
  3. Run the tests and watch them initially fail because the code doesn't exist yet.
  4. Write code. Execute unit tests again until the tests pass.
  5. Refactor the existing code to pass the tests while improving design, readability, and maintainability.

What Are BDD Testing Frameworks?

BDD testing frameworks are tools that provide support for implementing BDD practices and automating BDD tests. They bridge the gap between business requirements and test automation.

How To Do BDD Testing with Katalon and Cucumber? 

Katalon logo

Katalon is a comprehensive QA solution that allows teams to create automation tests for web, API, and mobile, execute them in the cloud across a wide range of browsers, then generate in-depth reporting.

Katalon supports BDD testing with Cucumber, giving testers the best of both worlds: the BDD capabilities of Cucumber and the rich features provided by Katalon:

  • Import BDD feature files into Katalon to leverage its centralized test management features, or pull them directly from Jira using the Katalon Jira integration's JQL import
  • Easily create test scripts with Katalon’s low-code test authoring features
  • Link BDD steps with test scripts to track test results
  • Generate detailed test reports in BDD style

After downloading Katalon Studio, simply navigate to File > New > BDD Feature File to create a Cucumber feature file in Katalon.

Give your feature file a name. If you check the “Generate sample feature file template,” a full BDD script template written in Gherkin will be created for you to freely edit.

Generate sample feature file template for BDD testing in Katalon Studio

Here is a simple Gherkin scenario as shown below:

At this stage, you should see that there is a yellow highlight on each step in the feature file. This occurs because we have not yet created the step definition or test script for each step (i.e., missing glue code: small pieces of code or scripts that connect two technologies together, which are Cucumber and Katalon in this context).

Add the Gherkin scenario

Therefore, the next step involves creating the step definition in the step file. In the left sidebar, navigate to Include > features > scripts > groovy > (default package). Here you can right click, select New > Step Definition and create a Groovy script.

Create a new Groovy script to add step definition

As you can see, each of the BDD steps above has been linked to its corresponding step definition.

import io.cucumber.java.en.Given
import io.cucumber.java.en.When
import io.cucumber.java.en.Then

class LoginSteps {
    @Given("I navigate to the login page")
    def navigateToLoginPage() {
        // Implementation to navigate to the login page
    }

    @When("I enter my username")
    def enterUsername() {
        // Implementation to enter username
    }

    @When("I enter my password")
    def enterPassword() {
        // Implementation to enter password
    }

    @When("I click on the login button")
    def clickLoginButton() {
        // Implementation to click on the login button
    }

    @Then("I should be logged in successfully")
    def verifyLoginSuccess() {
        // Implementation to verify login success
    }
}

After that, you can start using the fast test authoring features of Katalon to transform the BDD feature file into a full test script within seconds. There are two notable methods:

  1. Built-in keywords: these are essentially code snippets that you can drag and drop to construct the test case.
  2. Record-and-Playback: this feature records the sequence of actions on your screen, captures the locators of the objects you interact with, and turns them into a script that can be re-executed across multiple environments. Simply put in your destination URL, choose the browser, and run.

Although these are low-code features, Katalon still allows you to view the full script, and you can complete the functions in the step definition file with the respective newly generated code. Finally, navigate to the top toolbar and click Run. The test runs automatically, and after it finishes you can see the BDD test results in Katalon TestOps.

It is easy to see how the capabilities of Cucumber are significantly expanded with Katalon:

  • Low code, fast test authoring instead of coding test scripts from scratch
  • Coding mode available for extra customization of test scripts
  • Cross-browser testing and execution for higher test coverage
  • Katalon test scripts can be maintained and easily updated through centralized management system, which is less resource intensive than Selenium scripts
  • Detailed test result generation in BDD style

Frequently asked questions

Henrik (Minh Huy) Dao

Minh Huy Dao (Henrik) is a Senior Quality Engineer at Katalon, where he has worked since 2023. He has nearly 10 years of experience in QA and test automation, including roles at TMA Solutions, Axon Active and Doctor Anywhere. His work spans automation with Java, JavaScript and WebdriverIO, as well as CI/CD with Jenkins and leading Scrum teams.

Connect on LinkedIn →
Get started

Test everything. Ship with confidence.

From generating test cases to spotting failures, Katalon's AI works across your entire pipeline, automatically.

Live webinar

The Next Evolution of Manual Testing: Introducing Katalon AI Test Runner

Learn how to grow your QA team's capacity in the age of AI, then watch Katalon AI Test Runner turn manual test cases into automated runs, live.

2:00 to 3:00 PM IST
Almas AhmedSenior Account Manager
Sumit WankhedeSolutions Engineer Manager
Register now