BDD Framework is a software development approach in which requirements are defined based on the behavior that the user expects to experience while interacting with the software. It reduces the gap between business analysts and technical people through improved communication.
It is evolved from TDD (Test Driven Development) where tests are written ahead of the code, but in the case of BDD, tests are user-focused and based on the system’s behavior.
Behavior-driven development makes use of a domain-specific scripting language which further converts the structured statements into executable tests. The acceptance criteria for a given test is used to validate the functionality
BDD focuses on:
- The starting point of the test
- Scope of test
- Test parameter
- Acceptance criteria of the test
- Failed Tests
BDD Key Aspects
It encourages developers to focus only on the required behaviors of the software.
It helps to avoid the induction of excessive code or unnecessary features.
It encourages collaboration between developers, testers, product owners, business analysts to build a shared understanding of the problem to be solved.
It produces system documentation that is automatically checked against the system’s behavior.
It helps to identify the key scenarios for user stories and eliminate ambiguities from requirements.
It helps to keep all the stakeholders on the same page.
How Business-Driven Development (BDD) works?
Behavior-driven development moves around conducting the behavior-specific tests, or functional requirements that emphasize on executable scenarios for the application. The below steps defined the BDD process:
- Identify goals in order to meet business requirements. This includes understanding the software in order to achieve a business perspective. This business goal drives the complete project. An ideal business goal is Specific, Measurable, Attainable, Relevant, and Time-bound (SMART).
- After the goal and timeline are defined, the next step is planning. It outlines all the alternative ways to meet the decided goals by analyzing user behavior.
- The next step is the prioritization of features, backlogs, etc. which is done by using value and complexity analysis. Value analysis helps to quickly determine low-cost, high-value features in the backlog. Complexity analysis helps to identify the correct development and collaboration approach of the project as well as individual features.
- Derive the technical feature from the specifications. This includes defining business rules, use cases, etc.
- In the next step, the descriptions of the technical features are used to generate requirements in GWT (Given When Then) format. Acceptance criteria for each requirement are defined. Then statement defines the acceptance criteria.
- Behavioral tests are created for each requirement before development starts. Initially, before development begins, it is expected all of the behavioral tests will fail, but as the development of the product progresses, the tests will begin to pass. Once all of the behavioral tests are considered passing, the product is ready.
BDD Testing Example
‘Given‘ describes the initial context for the scenario
‘When‘ describes the action that the actor in the system going to perform
‘Then‘ describes the expected outcome of that action
Let see below the structure of the requirement in BDD from the below example
Given user is in the login page of Gmail account
When user enters correct email Id and password
Then user will be successfully logged in to its account
Advantages of BDD
- Better communication between developers, testers, and product owners.
- Acceptance criteria are defined prior to the development
- It focusses on verifying the behavior rather than tests.
Disadvantages of BDD
- Prior experience of TDD is required, before starting with BDD.
- BDD is incompatible with the waterfall approach.
- BDD may not be effective if the requirements are not properly specified.
- Testers using BDD need to have sufficient technical skills.