Behavior Driven Development (BDD) – Understand in Easy Words

BDD is an advanced and faster transformation of traditional SDLC model i.e. Waterfall model. Waterfall model is a linear sequential arrangement of different phases of software development activities. It is called as linear sequential phases as each phase is dependent on previous phase deliverables or output. We can not move to next phase until previous phase is completed. These phases are Requirements, Design, Implementation, Verification and Maintenance.

Requirements were gathered from different sources and documented in a lengthy document. Everyone including Client, Developer, Tester used to go through those vague requirements and have own understanding. Developers used to develop functionalities as per their understanding of requirements and Testers used to create Test scenarios and test cases to test those requirements. Developers or other stakeholders have less or no visibility of tests written or planned by Testers in advanced. During testing phase, a lot of requirement gaps, functionality missing, understanding gaps, misinterpretation of requirements used to be surfaced.  All it used to take more time, resource and cost. The main reason of all these were less collaboration among stakeholders of project.

To improve above process, “Tests” were moved in beginning which is also called as Test First approach. The purpose of this was to increase the visibility of planned tests for execution at starting of Development so that developer can keep those scenarios in mind and develop functionalities. It is also termed as TDD i.e. Test Driven Development. It was also not able to establish the required collaboration among stakeholders of project. TDD is an approach of writing tests before actual code to feature. When all tests are passed, development of feature is considered to be completed. But TDD was not understandable by all stakeholders of project as it was more technical. TDD has a lack of common view or was not able to keep everyone on same page of understanding of requirements.

The collaboration version of TDD is known as Acceptance Test Driven Development i.e. ATDD where people from different domain e.g. Developer, Testers, Business Analyst, Clients, end users etc. collaborate together and decide acceptance tests in advance of application. Major difference between TDD and ATDD is that TDD focuses more on Unit testing while ATDD focuses more on acceptance testing.

BDD combines the principles of TDD (Test Driven Development) and ATDD (Acceptance Test Driven Development). BDD is an agile software development process (Not a Software Testing process) which defines expectation from an application to behave from intended user prospective.

BDD focuses more on Behavior of application instead of its technical details which helps everyone related to Application to be on same page. It explains behaviour of application in such a way that everyone has same understanding. It is an approach of writing behavior of an application in a Domain Specific Language (DSL) E.g. Gherkin, to reduce the communication gap between technical and non-technical people. A DSL language is something which can be understandable by both Technical and non-technical people and which fills the gap between them.

In TDD we define “Tests” while in BDD we define “Behavior”.  Since TDD is a Test First practice, so BDD is. BDD is very important in agile process where software development is faster and change requirements are responded quickly without excessive overhead.

Official website of Cucumber explains it very nicely:-

Behaviour-Driven Development (BDD) is a set of practices that aim to reduce some common wasteful activities in software development:

  • Rework caused by misunderstood or vague requirements
  • Technical debt caused by reluctance to refactor code
  • Slow feedback cycles caused by silos and hand-overs

BDD aims to narrow the communication gaps between team members, foster better understanding of the customer and promote continuous communication with real world examples.

Keywords in BDD:-

  1. A requirement is considered as a Feature which follows Role-Functionality-Result (As a – I want- So That) formula.
  2. A feature will have multiple scenarios.
  3. Each scenario is written in form of Given (Pre-conditions/ Context), When (Action/Event Performed) and Then (Result/Outcomes) format.

At the era of Waterfall Model/Traditional SDLC model:-

Requirement document for Login into Facebook:-

There will be a web page for login to Facebook. This page will be developed using JavaScript front end framework. User needs to provide their credentials to login to their account.  Registered user detailed will be kept in “User Account” table. If user passes correct details, user will be navigated to home page. If user passed incorrect details, user will see an error message.  Login page will contain Facebook logo and title as “Login to application”.

At the era of BDD:-

Feature: Facebook Login
  As an End User
  I want to login to my Facebook account
  So That I can access my Facebook account

  Scenario: Design of Facebook login page
    Given A web browser is launched
    When Login page of Facebook is launched
    Then End user should see a web page with title “Login to Facebook”
    And End user should see Facebook logo at the login page
    And End user should see a input box field for “Email Address”
    And End user should see a input box field for “Password”
    And End user should see a button for “Login”

  Scenario: Successful login to Facebook account
    Given A web browser is launched
    And Login page of Facebook is launched
    And End user has valid credentials
    When End user enters valid email address in input box field for “Email Address”
    And End user enters valid password in input box field for “Email Address”
    And End user clicks on Submit button
    Then End user should be navigated to Facebook Home page

  Scenario: Unsuccessful login to Facebook account
    Given A web browser is launched
    And Login page of Facebook is launched
    And End user has invalid credentials
    When End user enters invalid email address in input box field for “Email Address”
    And End user enters invalid password in input box field for “Email Address”
    And End user clicks on Submit button
    Then An error message stating “Invalid Credentials” should be shown to end user

Hope, above article helps you to understand BDD. If you have any doubt or different understanding, please let me know in comments.

#ThanksForReading

Leave a Reply

Your email address will not be published. Required fields are marked *