Introduction
BDD (Behaviour driven development) adapted features of TDD(Test Driven Development) and extended a few little syntax, which made the Product Owner (PO Role of Scrum Process) or Business Analyst job easy to convert requirements into standard scripts, by analysing the behaviour of features required by customers. And the developer's job will be easy with this behaviour, scripts drive the development.
Pre-requisite
- A Developer should know python
- Recommend reading about TDD first.
We will see this BDD with an example of calci. BDD is following Gherkin syntax's. an example will be illustrated below Gherkin syntax's
- Feature:
- Scenario:
- Given
- When
- Then
Requirement from the customer: Build a calculator app, for 2 numbers addition and substraction
For BDD, we will a "behave" package, which is available in python. Install the package with the following command
Convert requirements into feature file like below using Gherkin syntax, File name: calci.feature
For Gherkin syntax keywords, write steps like below
File name: calci_steps.py
Below is the calci.py file which actually contains business logic. Actually, here to develop this calci.py, we need to follow TDD. As the article is to know about BDD. I am putting code directly.
Normally, a file/folder structure should look like the one below.
![]()
Now execute the feature file with a behave command,
If you are creating a virtual environment, execute with the below command.
Switch to virtual env using command,
Run test with command,
Below is the output window,
![]()
Summary
In this article, we understood about BDD execution. FYR I attached a source code zip file to this article.