SlideShare a Scribd company logo
1 of 16
Download to read offline
Behavior Driven
                      Development
                      Writing Software That Matters

                              Tarun Sukhani




Friday, May 11, 12                                    1
What is BDD?
                     Behavior Driven Development (BDD) is about implementing
                     an application by describing its behavior from the
                     perspective of its stakeholders.

                                                    Test                    Acceptance Test
             Development Team                      Driven                       Driven            Business Analysts
              - Implement Vision                Development     Behavior       Planning           - Translate Vision
                                                                 Driven
                                                              Development




                                                               Domain
                                   Incidental Stakeholders     Driven       Core Stakeholders
                                    - Support Vision           Design       - Articulate Vision


Friday, May 11, 12                                                                                                     2
How did BDD originate?
         Analysis Phase of SDLC was being           TDD is not a design tool - it leads
           overlooked for automation...             to emergent design at a granular
                                                                 level...

                     Planning
                                            This in turn leads to brittleness
                     Analysis               because the structure of the
                                            objects we are testing starts to
                     Design                 take precedence over the
                                            interaction and behavior of those
             Implementation
                                            objects.
                 Maintenance
Friday, May 11, 12                                                                        3
Principles of BDD
                           Enough is enough, or
                           YAGNI (You Ain’t Gonna
                           Need It)
                           Deliver stakeholder value
                           Everything is behavior
                           Outside-In Development


Friday, May 11, 12                                                                                                                                                                                           4
- Enough is enough. We should work to achieve the stakeholder’s expectations but avoid doing more than we need to do. YAGNI principle.
• Deliver stakeholder value. There are multiple stakeholders— both core and incidental—and everything we do should be about delivering demonstrable value to them.
• It’s all behavior. Just as we can describe the application’s behavior from the perspective of the stakeholders, we can describe low-level code behavior from the perspective of other code that uses it.
BDD by example
   GroupEat
  An application that allow groups of people to order food online from registered
  restaurants and have their order emailed or SMSed to the restaurants for pickup or
  delivery.
      Features should                                                                                                            Highlights
                                                                       Used to group            Features are not              potential pitfalls
      only be included
                                                                         features                 the same as                   or areas of
       if they help to
                                                                         together                   stories!                  greater concern
          fulfill this                       SMART




         Establish                      Identify                        Identify                 Identify                    Identify risks
         vision or                    outcomes or                    feature sets or           features and                      and
         purpose                         goals                          themes                    stories                    assumptions

                                   1. Able to order from different                          1. Restauranteurs should be     1. SMS integration
   Make group food ordering to                                       1. User registration
                                   restaurants                                              able to create menus            2. Market interest
   multiple restaurants easy and                                     2. Order management
                                   2. Keep track of group and                               2. Users should be able to
   convenient                                                        3. Expense tracking
                                   individual food expenses                                 see a history of their orders
Friday, May 11, 12                                                                                                                                 5

SMART = Specific Measurable Achievable Relevant Time-boxed
GroupEat: Features and Stories
                     Evo                                                                       he
                                                                                          ean t e
                               pE at mu
                           Grou sers to
                                         st
                                                      Barack              er,
                                                                                     um
                                                                              do yo rder or th
                                   u                                 By us ing the o it?
                            allow ir order                                 ak             ng
                                     e
                              eck th ry.                             one m ne receivi
                            ch                                              o
                                                                                                     wo
                                   histo                                                       ave t
                                                                                            eh
                                                                                  t case, w fore two
                                                                          In tha nd there
                                                                                     a            res.
                                                                             r oles, ent featu
                                                                                   differ
             Stakeholder                          Business Analyst


                     Evo                              Barack                           ke  them
                                                                                 ’s ma tures:
                                                                                                  two
                                                                             let
                                                                     G reat, rate fea                 t to
                                            ant
                                   OK. I w le                               sepa           er, I wan at I
                            Yeah,         be ab                                ac   ustom tory so th .
                                  oles to                                1. As rder his pending
                           both r          rder                                     o              s
                               to  check o                              check my much I’m I want to
                                                                                     w              r,
                                     history.                             kn ow ho tauranteu y so that I
                                                                                       s               r
                                                                           2 .A s a re rder histo arning.
                                                                                         o                e
                                                                                   k my much I’m
             Stakeholder                          Business Analyst          chec how
                                                                               know


Friday, May 11, 12                                                                                            6
GroupEat: Scenarios
                     Barack                        two
                                             have ith
                                                                          Kim                            scena s
                                                                                                                rio f or
                                                                                                                         the
                                         ,I                                                        one                            t
                               He y Kim discuss w g                                        G  reat, ustomer i Restauran
                                         to             kin                                           c            r om         .50
                               features volve chec or                                                   Item A f otal is $4
                                           in          is f                                      order nd my t rant D on
                                   . Both ory. One ther
                               you hist                                                   1. If I ay 1 a
                                                       he o                                                            stau         nI
                                 o rder           and t eur.                                 Bo  nD         fr o m Re 3.00, the r
                                               er                                                    em C total is $ my orde
                                         stom taurant                                               t
                                                                                               and I d my
                                 the cu he res                                                                               on
                                      f or t                                                          an               total
                                                                                                Day 2 see $7.50 page.
           Business Analyst                                              Tester                  shoul
                                                                                                       d
                                                                                                                histor
                                                                                                                        y




                     Evo                        in
                                       at rem to filter
                                                        .I
                                                  ds me by                Barack                               ak th
                                                                                                                    ose
                                  , th                                                                       re
                              Yeah be able                 see                                     we  can b er into
                                     to              hat I ly                              , then ures furth iewing
                               want anges so t ll on                                     OK       eat             v
                                        r
                                 date tals that
                                                      fa
                                                                ge.                         two f at include range,
                                           to            te ran                                     th
                                                                                              ories als by dat n a
                                                                                                                  e
                                  order specific da er by                                    st
                                                                                                     tot
                                                           lt                                                      eve
                                  w
                                            a
                                    ithin o like to fi items.                                   order urant, or m.
                                              s
                                        I’d al t and foo
                                                              d                                    resta icular ite
                                                an                                                      part
                                       re staur
               Stakeholder                                            Business Analyst
Friday, May 11, 12                                                                                                                       7
Automating Scenarios
                     The Business Analyst ensures that the stories and respective
                     scenarios use the language of the stakeholders (ubiquitous
                     language)
                     Where it makes sense to do so, scenarios or test cases are
                     automated. Scenarios are made up of individual steps which
                     drive the direction of the development effort.
                     One of the most important characteristics of BDD is that the
                     scenarios are easy to automate and modify yet are still
                     understandable to the stakeholder.
Friday, May 11, 12                                                                  8
Gherkin: DSL for BDD
                     Gherkin is a Domain Specific Language (DSL) for BDD
                     It is i18n compliant and currently supports 35 different
                     languages
                     Gherkin grammar has the following keywords:
                     ★ Feature
                     ★ Background
                     ★ Scenario
                     ★ Scenario outline
                     ★ Scenarios (or examples)
                     ★ Given
                     ★ When
                     ★ Then
                     ★ And (or but)
                     ★ | (which is used to define tables)
                     ★ """ (which is used to define multiline strings)
                     ★ # (which is used for comments)
Friday, May 11, 12                                                              9
GroupEat: Sample Feature
            i18n support { # language: en
             feature tags { @approved @release1.0
      feature description { Feature: Customer checks order history
                              In order to monitor spending
                              As a customer
                              I want to check my order history

             scenario tag {    @sprint1
          typical scenario {   Scenario: Default order   history (no filter)
                               @sprint2
     edge case scenario {      Scenario: Order history   with date range filter
                               @sprint2
     edge case scenario {      Scenario: Order history   with restaurant filter
                               @wip @sprint3
     edge case scenario {      Scenario: Order history   with menu item filter




Friday, May 11, 12                                                                10
GroupEat: Scenario Steps
                     Given: Indicates something that we expect to be true in a
                     scenario; e.g., Given I am logged in as a customer. It is not
                     the same as a precondition.
                      When: Indicates the event in the scenario. Preference is for
                     a single event in a scenario; e.g., When I view order history
                     page
                     Then: Indicates an expected outcome. OK to have more than
                     one (hence the And and But); e.g., Then I should see $7.50
                     for the order total.
Friday, May 11, 12                                                                   11
Scenario Styles
                 Declarative                                             Imperative
                                                        Scenario: Default order history (no filter)
Scenario: Default order history (no filter)
                                                          Given I am logged in as a customer
  Given I am logged in as a customer
                                                          And I go to the order form
  And I order Item A from Restaurant B
                                                          And I select “Restaurant B” from “Restaurants”
  And I order Item C from Restaurant D
                                                          And I select “Item A” from “Items”
  When I go to the order history page
                                                          And I press “Add Item”
  Then I should see $7.50 for my order total
                                                          And I select “Restaurant D” from “Restaurants”
                                                          And I select “Item C” from “Items”
                                                          And I press “Add Item”
                                                          When I go to the order history page
                                                          Then I should see $7.50 for my order total


    Tend to be more customized to each scenario. Less      More composable, meaning we can generally support
    verbose, so less amenable to reuse.                    more scenarios with fewer step definitions




Friday, May 11, 12                                                                                             12
Organizing Features
                     For larger projects or for features with lots of scenarios, we
                     can create subdirectories for each feature, with multiple files
                     in each subdirectory and with cohesive subsets of scenarios
                     in each file
                     We can also choose to organize by feature sets or themes,
                     each in its own subdirectory.
                     features
                       order management
                         order placement
                         order history
                       user registration
                         customer registration
                         restauranteur registration
                       restaurant management
                       customer management
Friday, May 11, 12                                                                13
Tag usage
                     Once we get a scenario passing, any subsequent failure is
                     considered a regression. We want some mechanism to fix
                     failing scenarios quickly.
                     Tags allow for this by running only those features or
                     scenarios that we specify.
                     Other uses for tags include identifying scenarios only to be
                     run in a certain environment, representing different sorts of
                     testing, or related to a features set or theme.
Friday, May 11, 12                                                                   14
End with more Gherkin...
                     Background: Lets us write steps that will be invoked before
                     every scenario in a given feature.
                     Multiline Text: For software that uses text files as either input
                     or output.
                     Tables in Steps: When specifying tabular data in steps,
                     usually used with Given or Then.
                     Scenario Outlines: For similar scenarios, we can define an
                     outline for a scenario once, with placeholders for the values
                     that might change from scenario to scenario.
Friday, May 11, 12                                                                   15
GroupEat: Coding Example
                      Ruby on Rails Outside-In Development with Cucumber
                 1.      Start with a scenario. Make user you understand the expected outcomes and how the UI should support a
                         user interacting with the application
                 2.      Run the scenario with Cucumber. This reveals what step definitions need to be defined.
                 3.      Write a step definition for the first step. Run the scenario with Cucumber and watch it fail.
                 4.      Drive out the view implementation. You’ll discover assigned instance variables, controllers, controller actions,
                         and models that the view will need in order to do its job.
                 5.      Drive out the controller implementation, ensuring that the instance variables are properly assigned. With the
                         controller in place, you’ll know what models it needs to do its job.
                 6.      Drive out the models, ensuring that they provide the methods needed by the view and the controller. This
                         typically leads to the fields required for the database.
                 7.      Once you have implemented all the models and the methods you discovered are needed, execute the scenario
                         with Cucumber again to make sure the step is satisfied.

Friday, May 11, 12                                                                                                                      16

More Related Content

What's hot

Visual resume of Samir Penkar
Visual resume of Samir PenkarVisual resume of Samir Penkar
Visual resume of Samir PenkarSamir Penkar
 
Quality Prediction for Speech-based Telecommunication Services
Quality Prediction for Speech-based Telecommunication ServicesQuality Prediction for Speech-based Telecommunication Services
Quality Prediction for Speech-based Telecommunication ServicesFörderverein Technische Fakultät
 
Merging media access 360 roi workshop gamification 3.0
Merging media access 360 roi workshop   gamification 3.0Merging media access 360 roi workshop   gamification 3.0
Merging media access 360 roi workshop gamification 3.0Scott Dodson
 
Building Self-Configuration Data Centers with Cross Layer Co-Evolution
Building Self-Configuration Data Centers with Cross Layer Co-EvolutionBuilding Self-Configuration Data Centers with Cross Layer Co-Evolution
Building Self-Configuration Data Centers with Cross Layer Co-Evolutionpaskorn
 
Understanding Interaction Design
Understanding Interaction DesignUnderstanding Interaction Design
Understanding Interaction DesignDavid Rondeau
 
Agile NCR 2013 - Seema Verma - energizing hr for agile excellence-competency...
Agile NCR 2013 - Seema Verma -  energizing hr for agile excellence-competency...Agile NCR 2013 - Seema Verma -  energizing hr for agile excellence-competency...
Agile NCR 2013 - Seema Verma - energizing hr for agile excellence-competency...AgileNCR2013
 
Evidence for Designing Patient Rooms at Northwest Community Hospital
Evidence for Designing Patient Rooms at Northwest Community HospitalEvidence for Designing Patient Rooms at Northwest Community Hospital
Evidence for Designing Patient Rooms at Northwest Community HospitalCannonDesign
 
Business Patterns presentation @ Oredev 2012
Business Patterns presentation @ Oredev 2012Business Patterns presentation @ Oredev 2012
Business Patterns presentation @ Oredev 2012allan kelly
 
M2 m etsi_oktober_v1 0_241012_final[2]
M2 m etsi_oktober_v1 0_241012_final[2]M2 m etsi_oktober_v1 0_241012_final[2]
M2 m etsi_oktober_v1 0_241012_final[2]butler-iot
 
Microsoft Licensing Business Continuity Plan
Microsoft Licensing Business Continuity PlanMicrosoft Licensing Business Continuity Plan
Microsoft Licensing Business Continuity PlanElaine Noble
 
Building Your Brand - Steve O’Donnell - Talent4Tech
Building Your Brand - Steve O’Donnell - Talent4TechBuilding Your Brand - Steve O’Donnell - Talent4Tech
Building Your Brand - Steve O’Donnell - Talent4TechTalent4Tech
 
Lean presentation april 8, 2009
Lean presentation april 8, 2009Lean presentation april 8, 2009
Lean presentation april 8, 2009debbiedetech
 

What's hot (18)

Visual resume of Samir Penkar
Visual resume of Samir PenkarVisual resume of Samir Penkar
Visual resume of Samir Penkar
 
Quality Prediction for Speech-based Telecommunication Services
Quality Prediction for Speech-based Telecommunication ServicesQuality Prediction for Speech-based Telecommunication Services
Quality Prediction for Speech-based Telecommunication Services
 
Tata Chemicals, Mithapur
Tata  Chemicals, MithapurTata  Chemicals, Mithapur
Tata Chemicals, Mithapur
 
+15 team v3
+15 team v3+15 team v3
+15 team v3
 
Merging media access 360 roi workshop gamification 3.0
Merging media access 360 roi workshop   gamification 3.0Merging media access 360 roi workshop   gamification 3.0
Merging media access 360 roi workshop gamification 3.0
 
Building Self-Configuration Data Centers with Cross Layer Co-Evolution
Building Self-Configuration Data Centers with Cross Layer Co-EvolutionBuilding Self-Configuration Data Centers with Cross Layer Co-Evolution
Building Self-Configuration Data Centers with Cross Layer Co-Evolution
 
Understanding Interaction Design
Understanding Interaction DesignUnderstanding Interaction Design
Understanding Interaction Design
 
Agile NCR 2013 - Seema Verma - energizing hr for agile excellence-competency...
Agile NCR 2013 - Seema Verma -  energizing hr for agile excellence-competency...Agile NCR 2013 - Seema Verma -  energizing hr for agile excellence-competency...
Agile NCR 2013 - Seema Verma - energizing hr for agile excellence-competency...
 
Evidence for Designing Patient Rooms at Northwest Community Hospital
Evidence for Designing Patient Rooms at Northwest Community HospitalEvidence for Designing Patient Rooms at Northwest Community Hospital
Evidence for Designing Patient Rooms at Northwest Community Hospital
 
MindsetterLIVE
MindsetterLIVEMindsetterLIVE
MindsetterLIVE
 
Business Patterns presentation @ Oredev 2012
Business Patterns presentation @ Oredev 2012Business Patterns presentation @ Oredev 2012
Business Patterns presentation @ Oredev 2012
 
M2 m etsi_oktober_v1 0_241012_final[2]
M2 m etsi_oktober_v1 0_241012_final[2]M2 m etsi_oktober_v1 0_241012_final[2]
M2 m etsi_oktober_v1 0_241012_final[2]
 
CISA Summary V1.0
CISA Summary V1.0CISA Summary V1.0
CISA Summary V1.0
 
Microsoft Licensing Business Continuity Plan
Microsoft Licensing Business Continuity PlanMicrosoft Licensing Business Continuity Plan
Microsoft Licensing Business Continuity Plan
 
Building Your Brand - Steve O’Donnell - Talent4Tech
Building Your Brand - Steve O’Donnell - Talent4TechBuilding Your Brand - Steve O’Donnell - Talent4Tech
Building Your Brand - Steve O’Donnell - Talent4Tech
 
GEM Technical Concepts
GEM Technical ConceptsGEM Technical Concepts
GEM Technical Concepts
 
Lean presentation april 8, 2009
Lean presentation april 8, 2009Lean presentation april 8, 2009
Lean presentation april 8, 2009
 
Infographics
InfographicsInfographics
Infographics
 

Similar to Behavior driven development

Agile and lean product development the fundamentals
Agile and lean product development the fundamentalsAgile and lean product development the fundamentals
Agile and lean product development the fundamentalsRussell Pannone
 
Competency mapping
Competency mappingCompetency mapping
Competency mappingasthashukla
 
Virtual Success Equals Real Results - Training Magazine Conference 2013 Sessi...
Virtual Success Equals Real Results - Training Magazine Conference 2013 Sessi...Virtual Success Equals Real Results - Training Magazine Conference 2013 Sessi...
Virtual Success Equals Real Results - Training Magazine Conference 2013 Sessi...Brandon Williams
 
Developing an Analytical Mindset – Becoming an Analytical Competitor
Developing an Analytical Mindset – Becoming an Analytical CompetitorDeveloping an Analytical Mindset – Becoming an Analytical Competitor
Developing an Analytical Mindset – Becoming an Analytical CompetitorSAS Asia Pacific
 
Using Mobile as an Instrument to Affect Behavior
Using Mobile as an Instrument to Affect BehaviorUsing Mobile as an Instrument to Affect Behavior
Using Mobile as an Instrument to Affect BehaviorPhil Hendrix
 
Practices of an agile developer
Practices of an agile developerPractices of an agile developer
Practices of an agile developerDUONG Trong Tan
 
M12S07 - Retention & ESI - Paths to Success - Part Two
M12S07 - Retention & ESI - Paths to Success - Part TwoM12S07 - Retention & ESI - Paths to Success - Part Two
M12S07 - Retention & ESI - Paths to Success - Part TwoMER Conference
 
ALN-Bengaluru - Agile Management - Driving Leadership & Complexity of …
ALN-Bengaluru - Agile Management - Driving Leadership & Complexity of …ALN-Bengaluru - Agile Management - Driving Leadership & Complexity of …
ALN-Bengaluru - Agile Management - Driving Leadership & Complexity of …Ravi Kumar
 
Establishing a performance culture
Establishing a performance cultureEstablishing a performance culture
Establishing a performance culturethinktalentindia
 
5 Levels of Agile Planning Explained Simply
5 Levels of Agile Planning Explained Simply5 Levels of Agile Planning Explained Simply
5 Levels of Agile Planning Explained SimplyRussell Pannone
 
Lessons for Large Scale Lean and Agile Product Development - Atlassian Summit...
Lessons for Large Scale Lean and Agile Product Development - Atlassian Summit...Lessons for Large Scale Lean and Agile Product Development - Atlassian Summit...
Lessons for Large Scale Lean and Agile Product Development - Atlassian Summit...Atlassian
 
SharePoint MoneyBall: The Art of Winning the SharePoint Metrics Game by Susan...
SharePoint MoneyBall: The Art of Winning the SharePoint Metrics Game by Susan...SharePoint MoneyBall: The Art of Winning the SharePoint Metrics Game by Susan...
SharePoint MoneyBall: The Art of Winning the SharePoint Metrics Game by Susan...SPTechCon
 
10 tips for Chartering a Project
10 tips for Chartering a Project10 tips for Chartering a Project
10 tips for Chartering a ProjectGlen Alleman
 
An approach to business problem solution
An approach to business problem solutionAn approach to business problem solution
An approach to business problem solutionChinmay Bande
 
An approach to business problem solution
An approach to business problem solutionAn approach to business problem solution
An approach to business problem solutionMART Knowledge Center
 
Anti-patterns in Distributed Agile by Preethi Madhu
Anti-patterns in Distributed Agile by Preethi MadhuAnti-patterns in Distributed Agile by Preethi Madhu
Anti-patterns in Distributed Agile by Preethi Madhuagilencr
 
Charles Watt - The argument for supporting Open Access to incumbent shareholders
Charles Watt - The argument for supporting Open Access to incumbent shareholdersCharles Watt - The argument for supporting Open Access to incumbent shareholders
Charles Watt - The argument for supporting Open Access to incumbent shareholdersimec.archive
 
13 01-02 management by objectives
13 01-02 management by objectives13 01-02 management by objectives
13 01-02 management by objectivesMatt Schofield
 

Similar to Behavior driven development (20)

Agile and lean product development the fundamentals
Agile and lean product development the fundamentalsAgile and lean product development the fundamentals
Agile and lean product development the fundamentals
 
Competency mapping
Competency mappingCompetency mapping
Competency mapping
 
Virtual Success Equals Real Results - Training Magazine Conference 2013 Sessi...
Virtual Success Equals Real Results - Training Magazine Conference 2013 Sessi...Virtual Success Equals Real Results - Training Magazine Conference 2013 Sessi...
Virtual Success Equals Real Results - Training Magazine Conference 2013 Sessi...
 
Developing an Analytical Mindset – Becoming an Analytical Competitor
Developing an Analytical Mindset – Becoming an Analytical CompetitorDeveloping an Analytical Mindset – Becoming an Analytical Competitor
Developing an Analytical Mindset – Becoming an Analytical Competitor
 
Using Mobile as an Instrument to Affect Behavior
Using Mobile as an Instrument to Affect BehaviorUsing Mobile as an Instrument to Affect Behavior
Using Mobile as an Instrument to Affect Behavior
 
Practices of an agile developer
Practices of an agile developerPractices of an agile developer
Practices of an agile developer
 
M12S07 - Retention & ESI - Paths to Success - Part Two
M12S07 - Retention & ESI - Paths to Success - Part TwoM12S07 - Retention & ESI - Paths to Success - Part Two
M12S07 - Retention & ESI - Paths to Success - Part Two
 
ALN-Bengaluru - Agile Management - Driving Leadership & Complexity of …
ALN-Bengaluru - Agile Management - Driving Leadership & Complexity of …ALN-Bengaluru - Agile Management - Driving Leadership & Complexity of …
ALN-Bengaluru - Agile Management - Driving Leadership & Complexity of …
 
Establishing a performance culture
Establishing a performance cultureEstablishing a performance culture
Establishing a performance culture
 
AMI Presentation
AMI PresentationAMI Presentation
AMI Presentation
 
5 Levels of Agile Planning Explained Simply
5 Levels of Agile Planning Explained Simply5 Levels of Agile Planning Explained Simply
5 Levels of Agile Planning Explained Simply
 
Lessons for Large Scale Lean and Agile Product Development - Atlassian Summit...
Lessons for Large Scale Lean and Agile Product Development - Atlassian Summit...Lessons for Large Scale Lean and Agile Product Development - Atlassian Summit...
Lessons for Large Scale Lean and Agile Product Development - Atlassian Summit...
 
SharePoint MoneyBall: The Art of Winning the SharePoint Metrics Game by Susan...
SharePoint MoneyBall: The Art of Winning the SharePoint Metrics Game by Susan...SharePoint MoneyBall: The Art of Winning the SharePoint Metrics Game by Susan...
SharePoint MoneyBall: The Art of Winning the SharePoint Metrics Game by Susan...
 
10 tips for Chartering a Project
10 tips for Chartering a Project10 tips for Chartering a Project
10 tips for Chartering a Project
 
Managing multi-site teams on Agile Projects
Managing multi-site teams on Agile ProjectsManaging multi-site teams on Agile Projects
Managing multi-site teams on Agile Projects
 
An approach to business problem solution
An approach to business problem solutionAn approach to business problem solution
An approach to business problem solution
 
An approach to business problem solution
An approach to business problem solutionAn approach to business problem solution
An approach to business problem solution
 
Anti-patterns in Distributed Agile by Preethi Madhu
Anti-patterns in Distributed Agile by Preethi MadhuAnti-patterns in Distributed Agile by Preethi Madhu
Anti-patterns in Distributed Agile by Preethi Madhu
 
Charles Watt - The argument for supporting Open Access to incumbent shareholders
Charles Watt - The argument for supporting Open Access to incumbent shareholdersCharles Watt - The argument for supporting Open Access to incumbent shareholders
Charles Watt - The argument for supporting Open Access to incumbent shareholders
 
13 01-02 management by objectives
13 01-02 management by objectives13 01-02 management by objectives
13 01-02 management by objectives
 

Behavior driven development

  • 1. Behavior Driven Development Writing Software That Matters Tarun Sukhani Friday, May 11, 12 1
  • 2. What is BDD? Behavior Driven Development (BDD) is about implementing an application by describing its behavior from the perspective of its stakeholders. Test Acceptance Test Development Team Driven Driven Business Analysts - Implement Vision Development Behavior Planning - Translate Vision Driven Development Domain Incidental Stakeholders Driven Core Stakeholders - Support Vision Design - Articulate Vision Friday, May 11, 12 2
  • 3. How did BDD originate? Analysis Phase of SDLC was being TDD is not a design tool - it leads overlooked for automation... to emergent design at a granular level... Planning This in turn leads to brittleness Analysis because the structure of the objects we are testing starts to Design take precedence over the interaction and behavior of those Implementation objects. Maintenance Friday, May 11, 12 3
  • 4. Principles of BDD Enough is enough, or YAGNI (You Ain’t Gonna Need It) Deliver stakeholder value Everything is behavior Outside-In Development Friday, May 11, 12 4 - Enough is enough. We should work to achieve the stakeholder’s expectations but avoid doing more than we need to do. YAGNI principle. • Deliver stakeholder value. There are multiple stakeholders— both core and incidental—and everything we do should be about delivering demonstrable value to them. • It’s all behavior. Just as we can describe the application’s behavior from the perspective of the stakeholders, we can describe low-level code behavior from the perspective of other code that uses it.
  • 5. BDD by example GroupEat An application that allow groups of people to order food online from registered restaurants and have their order emailed or SMSed to the restaurants for pickup or delivery. Features should Highlights Used to group Features are not potential pitfalls only be included features the same as or areas of if they help to together stories! greater concern fulfill this SMART Establish Identify Identify Identify Identify risks vision or outcomes or feature sets or features and and purpose goals themes stories assumptions 1. Able to order from different 1. Restauranteurs should be 1. SMS integration Make group food ordering to 1. User registration restaurants able to create menus 2. Market interest multiple restaurants easy and 2. Order management 2. Keep track of group and 2. Users should be able to convenient 3. Expense tracking individual food expenses see a history of their orders Friday, May 11, 12 5 SMART = Specific Measurable Achievable Relevant Time-boxed
  • 6. GroupEat: Features and Stories Evo he ean t e pE at mu Grou sers to st Barack er, um do yo rder or th u By us ing the o it? allow ir order ak ng e eck th ry. one m ne receivi ch o wo histo ave t eh t case, w fore two In tha nd there a res. r oles, ent featu differ Stakeholder Business Analyst Evo Barack ke them ’s ma tures: two let G reat, rate fea t to ant OK. I w le sepa er, I wan at I Yeah, be ab ac ustom tory so th . oles to 1. As rder his pending both r rder o s to check o check my much I’m I want to w r, history. kn ow ho tauranteu y so that I s r 2 .A s a re rder histo arning. o e k my much I’m Stakeholder Business Analyst chec how know Friday, May 11, 12 6
  • 7. GroupEat: Scenarios Barack two have ith Kim scena s rio f or the ,I one t He y Kim discuss w g G reat, ustomer i Restauran to kin c r om .50 features volve chec or Item A f otal is $4 in is f order nd my t rant D on . Both ory. One ther you hist 1. If I ay 1 a he o stau nI o rder and t eur. Bo nD fr o m Re 3.00, the r er em C total is $ my orde stom taurant t and I d my the cu he res on f or t an total Day 2 see $7.50 page. Business Analyst Tester shoul d histor y Evo in at rem to filter .I ds me by Barack ak th ose , th re Yeah be able see we can b er into to hat I ly , then ures furth iewing want anges so t ll on OK eat v r date tals that fa ge. two f at include range, to te ran th ories als by dat n a e order specific da er by st tot lt eve w a ithin o like to fi items. order urant, or m. s I’d al t and foo d resta icular ite an part re staur Stakeholder Business Analyst Friday, May 11, 12 7
  • 8. Automating Scenarios The Business Analyst ensures that the stories and respective scenarios use the language of the stakeholders (ubiquitous language) Where it makes sense to do so, scenarios or test cases are automated. Scenarios are made up of individual steps which drive the direction of the development effort. One of the most important characteristics of BDD is that the scenarios are easy to automate and modify yet are still understandable to the stakeholder. Friday, May 11, 12 8
  • 9. Gherkin: DSL for BDD Gherkin is a Domain Specific Language (DSL) for BDD It is i18n compliant and currently supports 35 different languages Gherkin grammar has the following keywords: ★ Feature ★ Background ★ Scenario ★ Scenario outline ★ Scenarios (or examples) ★ Given ★ When ★ Then ★ And (or but) ★ | (which is used to define tables) ★ """ (which is used to define multiline strings) ★ # (which is used for comments) Friday, May 11, 12 9
  • 10. GroupEat: Sample Feature i18n support { # language: en feature tags { @approved @release1.0 feature description { Feature: Customer checks order history In order to monitor spending As a customer I want to check my order history scenario tag { @sprint1 typical scenario { Scenario: Default order history (no filter) @sprint2 edge case scenario { Scenario: Order history with date range filter @sprint2 edge case scenario { Scenario: Order history with restaurant filter @wip @sprint3 edge case scenario { Scenario: Order history with menu item filter Friday, May 11, 12 10
  • 11. GroupEat: Scenario Steps Given: Indicates something that we expect to be true in a scenario; e.g., Given I am logged in as a customer. It is not the same as a precondition. When: Indicates the event in the scenario. Preference is for a single event in a scenario; e.g., When I view order history page Then: Indicates an expected outcome. OK to have more than one (hence the And and But); e.g., Then I should see $7.50 for the order total. Friday, May 11, 12 11
  • 12. Scenario Styles Declarative Imperative Scenario: Default order history (no filter) Scenario: Default order history (no filter) Given I am logged in as a customer Given I am logged in as a customer And I go to the order form And I order Item A from Restaurant B And I select “Restaurant B” from “Restaurants” And I order Item C from Restaurant D And I select “Item A” from “Items” When I go to the order history page And I press “Add Item” Then I should see $7.50 for my order total And I select “Restaurant D” from “Restaurants” And I select “Item C” from “Items” And I press “Add Item” When I go to the order history page Then I should see $7.50 for my order total Tend to be more customized to each scenario. Less More composable, meaning we can generally support verbose, so less amenable to reuse. more scenarios with fewer step definitions Friday, May 11, 12 12
  • 13. Organizing Features For larger projects or for features with lots of scenarios, we can create subdirectories for each feature, with multiple files in each subdirectory and with cohesive subsets of scenarios in each file We can also choose to organize by feature sets or themes, each in its own subdirectory. features order management order placement order history user registration customer registration restauranteur registration restaurant management customer management Friday, May 11, 12 13
  • 14. Tag usage Once we get a scenario passing, any subsequent failure is considered a regression. We want some mechanism to fix failing scenarios quickly. Tags allow for this by running only those features or scenarios that we specify. Other uses for tags include identifying scenarios only to be run in a certain environment, representing different sorts of testing, or related to a features set or theme. Friday, May 11, 12 14
  • 15. End with more Gherkin... Background: Lets us write steps that will be invoked before every scenario in a given feature. Multiline Text: For software that uses text files as either input or output. Tables in Steps: When specifying tabular data in steps, usually used with Given or Then. Scenario Outlines: For similar scenarios, we can define an outline for a scenario once, with placeholders for the values that might change from scenario to scenario. Friday, May 11, 12 15
  • 16. GroupEat: Coding Example Ruby on Rails Outside-In Development with Cucumber 1. Start with a scenario. Make user you understand the expected outcomes and how the UI should support a user interacting with the application 2. Run the scenario with Cucumber. This reveals what step definitions need to be defined. 3. Write a step definition for the first step. Run the scenario with Cucumber and watch it fail. 4. Drive out the view implementation. You’ll discover assigned instance variables, controllers, controller actions, and models that the view will need in order to do its job. 5. Drive out the controller implementation, ensuring that the instance variables are properly assigned. With the controller in place, you’ll know what models it needs to do its job. 6. Drive out the models, ensuring that they provide the methods needed by the view and the controller. This typically leads to the fields required for the database. 7. Once you have implemented all the models and the methods you discovered are needed, execute the scenario with Cucumber again to make sure the step is satisfied. Friday, May 11, 12 16