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

Behavior Driven Development (BDD) Testing and Gherkin

Software testing is a method of ensuring that the software product works as expected and is defect free. TDD (Test Driven Development) is the process of writing test cases from a developers perspective even before the software is fully developed. As the product evolves, the tests may give false results. The recent transitions from waterfall to agile model has resulted in the evolution of BDD from TDD. BDD Is the technique of testing the system’s actual behaviors from the users perspective. This results in a better end product.


Advantages of BDD


• Uses simple human readable syntax which enables every team member to understand the language

• Allows members of all phases (Business Analysts, Developers and Testers etc) to engage in the product development

• Focuses on how the system should behave from the end users perspective

• Reduces coding costs by identifying bugs in the early stage of the development process

• Reuse of code helps in saving time


There are many tools that support BDD. Cucumber is one such tool that reads Gherkin tests. Gherkin is the language used by developers to write tests in cucumber. This language uses simple English making it easy to understand by every team member.




Image by @karenimages from unsplash

Gherkin Syntax


Feature : describes the feature of a software, related scenarios are grouped in a feature

Scenario : behavior of the system

Given : preconditions or initial context

When : event or action to be performed

Then : expected output

And / But : optional - used as conjunction elements


Example


Feature : Login functionality of a social networking site. It can have various scenarios.

Given : The user is already registered

When : The user enters the correct username and password

Then : The user should be redirected to the home page of the social networking site.


Now let’s see a real life example for better understanding.


Feature : Initial steps to be taken in order to plan for a picnic


Scenario 1 : With family

Given : Plan to go on a picnic

When : You want to spend family time

Then : Go with family


Scenario 2 : With friends

Given : Plan to go on a picnic

When : You want to meet friends

Then : Plan and go with friends


Scenario 3 : Decide on the venue

Given : Plan to go on a picnic

When : You know who’s coming

Then : Discuss with them and decide on the venue


Scenario 4 : Decide whether the picnic has to be indoor or outdoor

Given : Plan to go on a picnic

When : The weather is warm and good

Then : Plan for an outdoor picnic


Scenario 5 : Decide whether the picnic has to be indoor or outdoor

Given : Plan to go on a picnic

When : The weather is cold and raining

Then : Plan for an indoor picnic


Scenario 6 : Picnic at backyard

Given : Plan to go on a picnic

When : You do not want to step outside the home

Then : Plan for picnic in your backyard


Scenario 7 : Picnic at the beach

Given : Plan to go on a picnic

When : The weather is warn and you want to swim

Then : Go to the beach


Scenario 8 : Lakeside park

Given : Picnic is at the park

When : You want to do fishing

Then : Go to a lakeside park


Scenario 9 : Barbecue

Given : Picnic is at the park

When : You want to do grilling

Then : Go to a park that allows barbecue grilling


Scenario 10 : Decide on the date and time

Given : Going on a picnic

When : You know who’s coming

Then : Discuss with them and decide on the date and time of the event


Scenario 11 : Decide on the day

Given : Every one is free on a weekday

When : You want to stay away from the crowds

Then : Plan the picnic for a weekday


Scenario 12 : Decide on the day

Given : Members are not available on a weekday

When : You want to stay away from the crowds

Then : Plan at your backyard or a remote place on a weekend


Scenario 13 : Reserve the venue

Given : Plan to go on a picnic

When : You decide on the guest list, date/time and venue

Then : Make a reservation for the venue on the event day/time


Scenario 14 : Decide on the things to be taken

Given : Plan to go on a picnic

When : You decide on the guest list, date/time and venue

Then : Create a checklist for the things to be taken to the picnic


Feature : Things to take for a picnic


Scenario 15 : Skin protection

Given : The picnic is outdoors

When : It is sunny outside

Then : Take a sunscreen to protect your skin


Scenario 16 : Clothes to wear

Given : The picnic is outdoors

When : It is very hot outside

Then : Wear summer clothes


Scenario 17 : Extra clothes to layer

Given : The picnic is outdoors

When : The weather is windy

Then : Take some clothes to layer


Scenario 18 : Take drinks

Given : The picnic is outdoors

When : It is very hot outside

Then : Take lots of water / cold drinks to beat the heat


Scenario 19 : Take swimwear

Given : Picnic is at the beach

When : You want to swim in the ocean

Then : Take swimwear


Scenario 20 : Clothes to change

Given : Picnic is at the beach and You want to swim in the ocean

When : You want to go out directly after the picnic

Then : Take clothes to change


Scenario 21 : Beach blanket

Given : Picnic is at the beach

When : Want to sit and eat

Then : Take a beach blanket


Scenario 22 : Picnic blanket

Given : Picnic is at the park

When : Want to sit and eat

Then : Take a picnic blanket


Scenario 23 : Beach Games

Given : Picnic is at the beach

When : Kids want to play at the beach

Then : Take beach ball and games


Scenario 24 : Outdoor games

Given : Picnic is at the park

When : Kids want to play

Then : Take outdoor games


Scenario 25 : Fishing

Given : picnic with family to a lakeside park

When : want to do fishing

Then : take fishing supplies



Feature : Food for the picnic


Scenario 26 : Home food

Given : Going with family

When : You don’t wish to eat outside food

Then : Pack some food from home and go


Scenario 27 : Restaurant food

Given : Going with family

When : You want a break from cooking

Then : Pick some food from a restaurant


Scenario 28 : Restaurant food

Given : Going with family

When : Want to eat at a restaurant afterwards

Then : Just pack some snacks


Scenario 29 : Potluck

Given : Going with friends

When : You plan for a potluck

Then : Decide on the dish you want to cook for the potluck


Scenario 30 : Groceries

Given : Cooking food for the picnic

When : The number of people coming and the dish is decided

Then : Plan on groceries needed


Scenario 31: Cook food at home

Given : Picnic with friends/ family

When : The date/time of the picnic is decided

Then : Decide on when to cook


Scenario 32 : Grilling supplies

Given : Picnic is at the park

When : You are going to grill food

Then : Take grilling supplies


Scenario 33 : Grilling food

Given : Picnic is at the park

When : You want to grill food

Then : Take food to be grilled


Scenario 34 : Trash bags

Given : Going on a picnic

When : You plan to eat food there

Then : Take trash bags for waste


Scenario 35 : Dinnerware

Given : Going on a picnic

When : You are taking food from home

Then : Take dinnerware to eat


Scenario 36 : Warm food

Given : Taking food to the picnic

When : You want the food to be warm

Then : Pack food in a thermal bag


Scenario 37 : Cold drinks

Given : Taking drinks to the picnic

When : You want the drinks to be cold

Then : Take the drinks in a travel cooler


Feature : After the picnic


Scenario 38 : Clean up

Given : Picnic is at a public place

When : Returning home

Then : Clean up the place


Scenario 39 : School

Given : Kids are coming to the picnic

When : Kids have school the next day

Then : Plan to return early


Scenario 40 : Homework

Given : Kids are coming to the picnic

When : Kids have homework to submit next day

Then : Check if it is completed


Gherkin is a good way to include non technical people to understand the system and thus deliver a better end product.

68 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page