what is bdd testing

What is BDD Testing?

If you are a tester I’m sure you have heard about BDD, but what is BDD testing, and why it is important for the business?

Well, BDD is an extension of the TDD (Test Driven Development) framework, which is a methodology that promotes the writing of our test cases before we start coding.

what is bdd testing

What is BDD testing?

BDD stands for Behaviour-Driven Testing. With this approach we change the way we think and design our test cases, focusing more on the behavior and the business side of the product, rather than on the test case itself.

In other words, BDD is an agile software development process used in software development that promotes collaboration between different parties inside the companies. For instance, we can involve product owners, testers and developers in the requirements definition and validation, and use that as a starting point for our software development.

This is possible because when we use BDD, we use natural language (plain English for example) to define the expected behaviour of our application under certain circumstances.

For example, we can have a user story written in plain English, and then we can start writing our acceptance criteria using BDD, in plain English.

As you can imagine, using this approach, we ensure better control over what is defined, and we have fewer chances of losing something between the translations from business to technology.

BDD vs TDD

BDD is an evolution of TDD that allows us to focus more on functional tests that help us to validate not only the application under tests from the technology point of view but also from the business perspective.

In other words, TDD has more focus on unit tests and BDD has more focus on functional tests.

What is Gherkins?

Gherkin is a readable language (can be plain English for example) that allows us to define behavior, and to use that definition on different stages such as during stories development, definition, and testing.

BDD Examples

For BDD we are going to use a language convention, named Gherkins, that allows us to use plain English as a base to allow us to define the application behavior using certain conventions.

Let’s say that we are creating an application for an online store and one of the requirements is that the store must accept product returns. Given that premise, we can write our scenario using gherkins in the following way:

Title: Product return

As a store employee
I must be able to accept returns
and modify the inventory

Scenario 1: Returned articles should be added to the inventory
Given a client that has bought a computer from the store
And the store has N computers in the inventory
When the costumer returns the computer
Then the inventory should display N+1 computers

As you can see in the above example, we have certain elements that we can highlight in the Gherkins format:

  • Title
  • Narrative
  • Acceptance Criteria

Each one of the elements represents a convention that every party involved in the definition can use as the acceptance criteria, for example, a product owner can write the definition in the above example, a developer can use it for developing the functionality and a tester can use it to write the acceptance criteria for the user story.

When we should use BDD?

As we can see the BDD development allows us to use plain English to define the behavior of a software application, bringing us the possibility of using that language as a base to write our code in a transparent way for product owners, business analysts, testers, and developers, among others.

BDD in autmation testing

BDD can be used in automation testing as well, so if you are already working on test automation or want to learn selenium webdriver, you can implement BDD in your project.

For this purpose, there are different libraries such as cucumber that allows us to easily implement BDD in our code.

Advantages of BDD testing

Using BDD has many advantages and based on my experience on many software projects, it’s a must nowadays for any team.

Some of the advantages are:

Shift left testing: Using this approach we can start testing the application from the very beginning of the development lifecycle, for example, by allowing the development team to test since the development of the application.

Low maintainability: As we are writing our “phrases” in plain English, it’s easier to maintain and to understand by different actors.

Allows code reusability: As we have everything defined in phrases, we can define them in code and reuse them again on several scripts.

Multi-language: We can use BDD to write automated scripts in almost any language.

Best BDD Frameworks:

Some well known BDD automation frameworks that I’ve used and I recommend are:

  • Quantum
  • Cucumber
  • Specflow
  • jBehave

Personally, I really love working with Cucumber on Python and Javascript and jBehave for Java.

Bottom line:

BDD is a great tool if you want your team to work using the same language, and to start testing earlier with a maintainable approach. I totally recommend the use of this framework in your development process as you will be able to save money by detecting issues earlier and having clear definitions about what’s need to be done and how.

1 thought on “What is BDD Testing?”

  1. Pingback: The Ultimate Comparison: Exploring the Pros and Cons of Popular Python Testing Frameworks - Relevant Codes

Leave a Comment

Scroll to Top