What is Behavior Driven Development? To understand more, let us have a quick look at Test Driven Development.
Test driven development is an approach where software is developed based on the automated tests, which is written from user requirement. Developer automates test and make it fail and then write code to pass the test and then improve the code to perfection. In this approach, there is a communication gap between technical and non-technical member of the team. Reason being the difficulty in reviewing the automated test by non-technical member. So then came Behavior driven development into picture where there is a layer introduced between user requirement and the automated test, which clearly define the behavior of the system in precise manner with clear example, which can be understood by both technical and non-technical member. Behavior driven development is an extension of test driven development by implementing domain specific language to reduce communication gap and improve collaboration among stakeholders.
Behavior Driven Development happens in 3 phases and they are Discovery, Formulation and Automation. In discovery phase, the team discuss and agree upon the behavior outcome of the system. In formulation phase, agreed behavior is documented using domain specific language. In automation Phase, automation of test case and implementation of code takes place. Automation test reports will be reviewed by business. Business, developer and tester get involved in all 3 phases.
Where does Gherkin comes in BDD?
Remember, I have mentioned about a layer between user requirement and automated test. That layer is called Gherkin. Gherkin is a simple, user friendly, non technical language used to express the scenario and behavior outcome of the system without going to its coding part. Product owner, developer and tester comes together to discuss the requirement and document the scenarios and its outcome. Keywords used in writing Gherkin are Features, Scenario, Scenario outline, Steps - Given, when, then, and/but, Background and Examples. I have defined important keywords below. Feature defines each independent functionality of a software. A feature can have multiple scenario. Scenario defines individual test case under a functionality. Each scenario should be very simple so that it makes a developer's job much easier. Steps has three parts to it. Given defines a condition of the software before performing an action. When defines a action performed by the user. Then defines the expected outcome. And/But can be used in the above steps if needed.
Here is a simple example to explain Gherkin syntax.
Feature : Keyword search
Scenario : Searching a particular keyword in google home page.
Given : I am in the google home page.
When : I type the word "Gherkin".
Then : It displays all the web page with the keyword "Gherkin".
So gherkin scripts break down each feature into scenarios which describe a single action to be performed and its behavior outcome.
Advantages of BDD
1.Improves communication and collaboration between customer, domain expert, business analyst, developer and quality analyst to give the product right.
2.Minimize cost and saves time by conveying clear system behavior to the stakeholders.
3.Maintain a single documentation for all stakeholders to check the expected behavior of the system.
Hope you enjoyed reading!