Benefits using Behavior Driven Development (BDD) in automation testing

Benefits using Behavior Driven Development (BDD) in automation testing

Why choose BDD?

There are several benefits that you can get by using BDD in your automation tests, such as:

  • Functionalities defined with descriptive scenarios.
  • Functionality scenarios are defined as features.
  • Scenario steps are reusable in the feature file.
  • Up to date use cases.
  • Understandable test scenarios for non technical people.
  • Allowing new members to get familiar with the product, and understand the business value.
  • You can easily solve whether reported issue is a bug or improvement 🙂

Defining feature and scenarios

For example lets say I have simple e-commerce website that has Products, Checkout, Login and Administration page. And we want to validate that the Checkout functionality is working as expected. Lets assume the following scenario that you are going to execute as a tester:

  1. Login into the site as a customer user.
  2. List all products.
  3. Select one product.
  4. Go to checkout.
  5. Pay for the product.
  6. Validate that the payment is successful.

Now we want to convert this manual scenario into BDD scenario so that it could be implemented in the automation suite. First we have to create feature file Checkout.feature, and in the feature file we would have to define the scenario. Each scenario starts with the keyword Scenario, and followed with colon and the name of the scenario.

Scenario: Product checkout validation for customer user

The scenario by it self is not going to do anything, we need to add the steps in the scenario. The steps are defined using the keywords Given, When, And, Then. The Given keyword is used when something is predefined, for example when the user has navigated to the website. The When keyword is used when we want to do some action, for example Login. The And keyword is used for chaining several actions, there is no specific behavior between When and And keywords, it depends on the style how the scenario is written. The Then keyword is used for the validation of the scenario, and this keyword is always last in the scenario, and best practice is to have one Then keyword per scenario.

Feature: Checkout feature

Background:

Given: The user has opened the e-commerce website

Scenario: Product checkout validation for customer user

When: The user has logged in the site as customer user
And: The user has listed all products
And: The user has selected one product
And: The user has opened the checkout page
And: The user has payed for the product
Then: Validate the payment is successful

Frameworks

There are several frameworks that you can choose from, and you are not going to make a mistake if you choose any of the frameworks that I’m going to list. Choosing the framework does not that you are going to start writing automation tests with ease. Choosing the framework mostly depends on which programming language suites you the most, or i.e. in which programming language you have more experience. This is going to allow you to progress in the automation development, and increase the productivity.

List of frameworks:

  • Cucumber using Java
  • Behat using PHP
  • Specflow using C#

All these frameworks support the BDD approach, and the syntax for defining the scenarios is the same. The difference is in the implementation of the scenarios.

Conclusion

When using BDD approach it does not benefit the team members when reading the scenarios of the automation suite, but it also benefits the automation tester forcing him to write the scenarios from business perspective. By reading this post you should be more familiar of the BDD approach used for automation testing, and choosing the most suitable framework, you start practicing this aproach.

One thought on “Benefits using Behavior Driven Development (BDD) in automation testing

  1. Pingback: Testing Bits – 10/15/17 – 10/21/17 | Testing Curator Blog

Leave a Reply

Your email address will not be published. Required fields are marked *