Behavior Driven Development (Brief Understanding)
Muhammad Kamran ?
CSM??, CSPO??, SAFe?? 5.0 Agilest, SFPC??, Kanban Foundation KIKF??, SFC??, Six Sigma Yellow Belt??, CSFPC??, SMPC??, PMEC??, Lean Six Sigma White Belt Certified - v4.0??
Behavior Driven Development is the way for software teams to make effective interactions between business and technical personnel.
The goal of BDD is that allows to describe an application’s behavior without involving development technicalities and designed an effective procedure to assistance the business stakeholders and the software technical team and Improves communication between stakeholders.
This structure allows a bridge between Programming language and Natural Language. It has plus points like test scripts can be written in any locale used by the stakeholders like English, French, Spanish etc.
Gherkin is the structured normal language that is used by any stakeholder to specify how they want the system to behave for given scenarios. It uses more about 10 keywords (Given, When, Then, And, But, Scenario, Feature, Background, Scenario Outline, Examples) which allow the language to be read and parsed by a tool called Cucumber. Every Cucumber project consist of Feature and Step Definition files
Features file contain high level description of the Scenario in Gherkin.
It consists of following steps to use Gherkin syntax:
Start User stories.
- FEATURE: Business Need
- SCENARIO: Test case / Business Case Title
- GIVEN is your setup
- WHEN is your action
- THEN is your assertion
Automate your BDD scenarios.
- First execution will fail as the feature is not yet implemented
Implement the feature
Run the automated BDD scenarios to show the feature is completed
Example of Feature file
Feature: The sum of two numbers Scenario: Add two numbers Given I have entered 250 into the calculator And I have entered 70 into the calculator When I press add
Then the result should be 320 on the screen
Step definition maps the Test case / Business Case Steps in the feature files to code.
Example of Step file
public class StepDefinitions { [Given(@"I have entered (.*) into the calculator")] public void GivenIHaveEnteredIntoTheCalculator(int num) { Console.WriteLine(num); } [When(@"I press add")] public void WhenIPressAdd() { Console.WriteLine("Add"); } [Then(@"the result should be (.*) on the screen")] public void ThenTheResultShouldBeOnTheScreen(int outcome) { if (outcome == 320) Console.WriteLine("Passed"); else { Console.WriteLine("Failed"); throw new Exception("Failed with Exception"); } }
} }
Conclusion:
BDD is a great way to improve clarity and collaboration within the team, it improves the quality of the application and removes barriers of communication between tech and non tech personnel