Monday 2 November 2015

Behaviour-Driven Development in a Nutshell


What is Behaviour-Driven Development?

Sharing the same vocabulary
   using specifications
   between all members of a project
       Customers
       Analysts
       Developers
       Testers

Like (Unit-)Test-Driven Development, but further up the Waterfall

It uses
   specifications
   Gherkin syntax
   Behaviour-Driven Development workflow

Specifications should be
   human-readable
      and
   executable

Example 1:
Feature: Search feature for users
This feature is very important because it will allow users to filter products
Scenario: When a user searches, without spelling mistake, for a product name present in inventory. All the products with similar name should be displayed
Given User is on the main page of www.myshopingsite.com
When User searches for laptops
Then search page should be updated with the lists of laptops
Example 2

Feature: Serve donuts
   In order to:
   As a:
   I want to:

Scenario: Buy last donut
   Given there is a donut on the tray
   And I have paid £0.89
   When I request the donut
   Then I should have a donut given to me

The Feature is a Narrative

The Scenario has
   steps
   an initial context
   actions
      and
   expected outcomes

The developer has to give an executable meaning to each step
    by writing step definitions

e.g.

Given /there is|are (\d*) donuts? left on the tray/ do |n|
   @donutTray = DonutTray.new(n.to_i)
end

or

@Giventhere is|are (\d*) donuts? left in the machine")
public void givenThereAreNDonutsLeft(String n)
 { this.donutTray = new DonutTray(Integer.parseInt(n));
 }

The Behaviour-Driven Development workflow is

Write a scenario
Watch it fail
Write code to make the scenario pass (including cycles of TDD - if you need to)
Refactor
   return to either Watch it fail
                  or Write Specification, as appropriate
Cucumber is
Cucumber has tools to declare a scenario as passed when each step has passed








No comments:

Post a Comment