What is BDD?
Behavior Driven Development (BDD) is an agile software development process which is evolved from Test Driven Development (TDD). The main advantage of BDD over TDD is the use of simple language which can be easily understood by all type of stakeholders (tech, non-tech).
User Stories and Scenario
Like other agile development process, User stories/Feature generally uses the Role-Feature –Benefit (RGB) model as mentioned below.
Generally BDD practitioner prefers the term “Scenario” instead of referring to tests and uses GHERKIN method to write Scenario (acceptance criteria) as described below.
Let us see few examples of Features and Scenarios:
Feature 1: As a customer, I would like to register, login and log out Instacart application so that I can buy groceries online.
@Scenario 1_1
Scenario: Register in Instacart
Given: the name, address and email id,
when: I try to register in Instacart
then: the registration is completed successfully.
@Scenario 1_2
Scenario: Login to Instacart
Given: the Instacart login credentials
when: I try to login with the valid user credentials
then: login to Instacart completed successfully.
@Scenario 1_3
Scenario: Log out Instacart
Given: I logged into Instacart,
when: I click the log out button
then: I am able to log out Instacart successfully.
@Scenario 1_4
Scenario: Invalid user credentials
Given: I am on Instacart login page,
when: I try to login with invalid user credentials
then: the error message “invalid email or password” is displayed successfully.
@Scenario 1_5
Scenario: Account locked
Given: I am on Instacart page,
when: I try to login with invalid user credentials more than three times
then: the account is locked and an email is triggered to the registered email id successfully.
@Scenario 1_6
Scenario: Account reset
Given: the user account is locked and I have an email to unlock,
when: I try to click unlock my account
then: account is un locked successfully.
@Scenario 1_7
Scenario: Password reset
Given: I am on Instacart login page,
when: I click forgot password and I entered email id and click Reset password
then: an email is triggered with password reset instructions.
Feature 2: As a customer, I would like to find items in Instacart application.
@Scenario 2_1
Scenario: Select Store
Given: I logged into Instacart,
when: I click the store page in home page
then: the store page is opened successfully.
@Scenario 2_2
Scenario: Search for the available items in the store page
Given: I logged into Instacart and selected the store page,
When: I enter the item name in search box
And : I click the search button
then: the item is listed in search page
@Scenario 2_3
Scenario: Search for Item not found
Given: I logged into instacart and selected the store page,
When: I enter the unavailable item name in the search box
And : I click the search button
then: the item unavailable error message is displayed
@Scenario 2_4
Scenario: Item details page
Given: I am in the available item search page and the item is listed,
when: I click the item
then: the item page with item description, price, quantity drop box and add to cart button is displayed successfully.
@Scenario_2_5
Scenario: Featured items at My Cart Page
Given: I am in the available item search page and the item is listed,
when: I click the item
then: the featured items are displayed at the bottom of the item page.
Feature 3: As a customer, I would like to add/remove items to cart in Instacart application.
@Scenario 3_1
Scenario : Add to cart
Given: I am in the item page in Instacart application,
when: I click add to cart
then: the item is added to cart successfully.
@Scenario_3_2
Scenario: Quantity change
Given: I am in the item page in Instacart application,
when: I click + button in quantity drop box,
then: the quantity is increased by one successfully.
@Scenario_3_3
Scenario: My Cart Page
Given: I added all the items to the cart,
when: I click the cart symbol
then: the my cart page with all the added items along with quantity and price is listed successfully.
@Scenario_3_4
Scenario: Suggested items at My Cart Page
Given: I added all the items to the cart,
when: I click the cart symbol
then: the suggested items to add next are displayed at the bottom of the my cart page.
@Scenario_3_5
Scenario: Remove items from My Cart Page
Given: I am in the my cart page,
when: I click the remove button
then: the item is removed successfully from the cart.
@Scenario_3_6
Scenario: Preferences in My Cart Page
Given: I am in the my cart page,
when: I click the preferences
then: the preference page with other options is displayed succesfully.
@Scenario_3_7
Scenario: Replacement for items in My Cart Page
Given: I am in the preference page,
when: I choose the replacement item
then: the replacement item page with quantity, price and choose as replacement button is displayed successfully.
@Scenario_3_8
Scenario: Choosing replacement items in My Cart Page
Given: I am in the replacement item page in the Instacart application,
when: I click “choose as replacement” button
then: the replacement option is updated successfully.
Feature 4: As a customer, I would like to checkout the Instacart application.
@Scenario 4_1
Scenario: Checkout in Add to cart page
Given: I am in the my cart page and total amount is less than $10,
when: I try to click the checkout button
then: the check out button is hidden with the message min $10 to checkout
@Scenario 4_2
Scenario: Checkout in Add to cart page
Given: I am in the my cart page and total amount is more than $10,
when: I click the checkout button
then: the check out page with two options of delivery and pick up is displayed successfully.
@Scenario 4_3
Scenario: Using pick up option in checkout page
Given: I am in the checkout page,
when: I click the pickup option,
then: the pickup check out page is displayed successfully.
@Scenario 4_4
Scenario: Choosing pick up location option in pickup checkout page
Given: I am in the pickup checkout page,
when: I click the pickup location,
then: the pickup locations are listed along with browse other locations option.
@Scenario 4_5
Scenario: Using delivery option in checkout page
Given: I am in the checkout page,
when: I click the delivery option,
then: the delivery check out page is displayed successfully.
@Scenario 4_6
Scenario: Choosing delivery time in checkout page
Given: I am in the delivery checkout page,
when: I click the delivery time
then: the delivery options with date, day and timing is displayed successfully.
@Scenario 4_7
Scenario: Adding payment method in checkout page
Given: I am in the checkout page,
when: I click the “add a payment method”
then: the payment option of “add new card” is displayed successfully.
@Scenario 4_8
Scenario: Adding credit/debit card details in checkout page
Given: I am in the checkout page and I click add new card,
when: I enter the credit/debit card details
then: the card details are added to the payment method successfully.
@Scenario 4_9
Scenario: Adding new credit/debit card details in checkout page
Given: I am in the checkout page and I click add new card,
when: there is an existing credit/debit card detail
And: I enter the new credit/debit card details
then: the new card details are added to the payment method successfully without affecting the existing credit/debit card details.
@Scenario 4_10
Scenario: Selecting appropriate new credit/debit card details in checkout page
Given: I am in the checkout page,
when: there are many existing credit/debit card details
then: I am able to select any one card for the payment method
@Scenario 4_11
Scenario: Selecting appropriate new credit/debit card details in checkout page
Given: I am in the checkout page,
when: there are many existing credit/debit card details
then: I am able to select my preferred card for the payment method
@Scenario 4_12
Scenario: Delivery tip in delivery checkout page
Given: I am in the delivery checkout page,
when: I click the delivery tip
then: I am able to increase or decrease the delivery tip amount
@Scenario 4_13
Scenario: Adding promo code in checkout page
Given: I am in the checkout page,
when: I click Add promo code or gift code
then: add promo or gift card page is appeared along with the Redeem button
@Scenario 4_14
Scenario: Adding promo code successfully
Given: I am in the add promo code page,
when: I add valid promo code or gift code and click Redeem
then: the promo code is applied successfully and the total amount is reduced as per the applied code.
@Scenario 4_15
Scenario: Invalid promo code
Given: I am in the add promo code page,
when: I add invalid promo code or gift code and click Redeem
then: the message “promotion code is invalid” is appeared successfully
@Scenario 4_16
Scenario: Place order
Given: I am in the check out page and all the required details are updated,
when: I click place order
then: the order is placed successfully.
Summary:
BDD let us develop, test from the view of the product owner and really helps to have a better communication with all stakeholders. Let’s try it out.