Types of Behavior Driven Development (BDD)

Introduction

Many test-automation-frameworks support Behavior Driven Development (BDD), but they differ in how they apply BDD.

There are at least three layers of BDD:

  • Keyword Driven BDD
  • Process Driven BDD
  • Model-Based Testing

Both Keyword and Process-driven will be explored in this article, while Model-Based Testing will come out next week.

Before BDD

Linear scripting is about hard coding each operational test step in a test case. Tools for capture and replay of user actions is just to visually hard code the test cases.

Structured scripting is about reusing the most used operational test steps by putting them in support libraries. 300 test will be updated with a single update in a support library, instead of reapplying the same change 300 times manually.

Data-driven automation runs the same test case multiple times, but with different parameters. It is very cheap to maintain.

Keyword-driven BDD (first layer)

The lowest version of BDD.

Keyword-driven automation is almost the same as structured scripting since it reuses the operational steps for multiple test cases. The difference is that the language is more readable in keyword-driven.

Structured scripting

A test case with structured scripting can look like this:

Browser.navigate("https://...com/webshop")
PageGeneral.cookiesButton.click()
pageTopMenu.tickets.click()
pageTickets.buyButton(click()
pageTickets.dropdown.select("adult")
pageTickets.continueButton.click()
pageZones.zoneSlider.slideTo("7")
pageZones.continueButton.click()
pageSpecialOffer.rejectButton.click()
assert( pageTickets.price.getText(), "18 €", "ERROR: price is incorrect")

All the operational steps can be reused in many test cases, and are categorized in this example with the Page Object Model.

Keyword-driven

A Keyword-driven will be much easier to read because it uses action keywords:

Navigate to "https://...com/webshop"
Click the tab "tickets"
Click button "Buy tickets"
Select dropdown "customer type" option "adult"
Click the "Continue" button
Move the slider to 7 zones
Click the "Continue" button
Click "Reject" button on the special offer window
Verify the price of 18 €

It can also use Gherkin keywords to split it into Preconditions (Given), Actions (when), and Assertions (Then):

Given the browser starts on https://...com/webshop
And accept the "cookies information"

When clicking the tab "tickets"
And clicking button "Buy tickets"
And selecting dropdown "customer type" option "adult"
And clicking the "Continue" button
And moving the slider to 7 zones
And clicking the "Continue" button
And rejecting the special offer window

Then the price must be 18 €

Process-driven (second layer)

Keyword-driven automation is describing the operational steps in a test case, while process-driven automation describes the business steps in a test case.

A test case written with process-driven automation has more focus on the needs than on the details. Therefore much easier to read for the business and see what the test case is actually testing

Given I am buying a ticket on the web shop
When buying a <child / adult / student / retired> ticket
And to travel <2 - 8> zones
Then the price should be <price>

The operational steps are hidden within the business steps:

Given I am buying a ticket on the web shop
Navigate to "https://...com/webshop"
When buying a <child / adult / student / retired> ticket
Click the tab "tickets"
Click button "Buy tickets"
Select dropdown "customer type" option "adult"
Click the "Continue" button
And to travel <2 - 8> zones
Move the slider to 7 zones
Click the "Continue" button
Click "Reject" button on the special offer window
Then the price should be <price> €
Verify the price of 18 €

Model-Based Testing (third layer)

Are you ready for the next level?

Coming soon.

Automation frameworks

The following automation frameworks support process-driven automation:

Please add any other frameworks in the comments

Add a Comment

Your email address will not be published.