KEMBAR78
The LAZY Developer's Guide to BDD (with Cucumber) | PDF
A LAZY Developer's
   Guide to BDD
  (with         )
        ~ Ng Tze Yang (aka TY)
2 weeks ago, i changed it to:


Everyone gets a little
  of         's ♥

                                2
A LAZY Developer's
   Guide to BDD
  (with         )

                     3
WTF is “LAZY” ??




                   4
LAZY= !(TATFT)



                 5
WTF is “TATFT” ??




                    6
7
Why Not TATFT ??




                   8
Why Not TATFT ??

* What is most important for a
  software ??




                                 9
Why Not TATFT ??

* What is most important for a
  software ??
  => Business Value




                                 10
Why Not TATFT ??

* What is most important for a
  software ??
  => Business Value
* How do we quantify BV ??




                                 11
Why Not TATFT ??

* What is most important for a
  software ??
  => Business Value
* How do we quantify BV ??
  => Behaviours


                                 12
BDD
~ Behaviour Driven Development ~




                                   13
BDD
~ Behaviour Driven Development ~
     “BDD facilitates agile development,
 which is an approach to develop functional
software, within reasonable timeline, making
 everyone happy, without killing anyone, or
          burning down any bank.”

                                               14
BDD's Core Principles




                        15
BDD's Core Principles

* It's all behaviour
    “ The business & technology people
    should be speaking the same words
      when referring to the same idea,
     there should not be any translator.”




                                            16
BDD's Core Principles

* It's all behaviour
    Behaviour: the addition of N values
    should yield the summation of them

    Example: the addition of 2 + 4 +1
             should yield 8



                                          17
BDD's Core Principles

* It's all behaviour
* Deliver stakeholder value
    “ Whatever u are doing, it should be
  delivering business value, or increasing
   ur ability to deliver value, if the activity
      doesn't acheive this, stop doing it”


                                                  18
BDD's Core Principles

* It's all behaviour
* Deliver stakeholder value
    “ Unit testing is important, as it makes
refactoring & regression testing easier, which
 eases maintenace and enhance ur ability to
         deliver newer features faster”


                                                 19
BDD's Core Principles

* It's all behaviour
* Deliver stakeholder value
* Enough is enough
   “ Do not overengineer, do not overdo
  upfront planning, analysis and design.
 Do just enough to get things started in the
              right direction”
                                               20
BDD's Core Principles

* It's all behaviour
* Deliver stakeholder value
* Enough is enough
“ When i wanna go to sentosa from my AMK
  home, i just goto gothere.sg to do a quick
check, and that's good enough, i don't need
   to get down to switching lanes on CTE,
                  blah blah. ”                 21
Cucumber ? Nice to Eat ?!




                            22
Cucumber ? Nice to Eat ?!

* a tool for functional testing




                                  23
Cucumber ? Nice to Eat ?!

* a tool for functional testing
* by Aslak HellesØy, & many other
  nice people




                                    24
Cucumber ? Nice to Eat ?!

* a tool for functional testing
* by Aslak HellesØy, & many other
  nice people
* allows non-technies to express
  app's functions in plain text


                                    25
Cucumber ? Nice to Eat ?!

* a tool for functional testing
* by Aslak HellesØy, & many other
  nice people
* allows non-technies to express
  app's functions in plain text
* plain text serves as documentation
  & executable examples
                                       26
Hmm .. Plain Text ?!




                       27
A Prettier Plain Text




                        28
The Title




            29
The Narrative




                30
Guideline for the Narrative




                              31
Guideline for the Narrative

* identify the stakeholder

    “ Eg. The system administrator”




                                      32
Guideline for the Narrative

* identify the stakeholder
* describe the feature he wants
   “ Eg. Trashing of all invalid purchase
           orders in the system”




                                            33
Guideline for the Narrative

* identify the stakeholder
* describe the feature he wants
* the reason for wanting it

      “ Eg. Prevent data corruption”



                                       34
The Acceptance Criterion




                           35
The Scenario's Title




                       36
The Scenario's Steps




                       37
Given | When | Then




                      38
Given | When | Then

* GIVEN ... setting up system to a
            known state
         “ Eg 1. Database setup ...
  Given the following users already exists”

           “ Eg 2. Visiting a Url ...
  Given I am on users management page”
      “ Eg 3. Ensure User's Login ...
   Given I already login as “HappyMan””
                                              39
Given | When | Then

* GIVEN ... setting up system to a
            known state
* WHEN ... exercising an event
         “ Eg. Pressing Button ...
         When I press “Help Me””




                                     40
Given | When | Then

* GIVEN ... setting up system to a
            known state
* WHEN ... exercising an event
* THEN ... verifying an outcome

        “ Eg. Seeing a message ...
   Then I should see “Login Successful””

                                           41
Save & Execute It !!
* Save at:
  <PROJECT_ROOT>
   `~ features/
      `- sign_up.feature




                              42
Save & Execute It !!
* Save at:
  <PROJECT_ROOT>
   `~ features/
      `- sign_up.feature
* Run with:
  #$ cucumber features

                              43
P1




P2



          44
45
46
47
48
49
50
51
Step Definitions




                   52
Save & Execute It !!
* Save as:
 <PROJECT_ROOT>
  `~ features/
     `- steps.rb




                              53
Save & Execute It !!
* Save as:
 <PROJECT_ROOT>
  `~ features/
     `- steps.rb
* Run with:
  #$ cucumber features

                              54
55
56
57
The Functional Test Model




                            58
The Generic Model


Cucumber
* cucumber exec
* features/*.feature
* features/*.rb




                             59
The Generic Model


Cucumber
* cucumber exec        Target App
* features/*.feature
* features/*.rb




                                    60
The Generic Model


Cucumber
* cucumber exec                 Target App
* features/*.feature
* features/*.rb

                       Driver


                                             61
The Generic Webapp Model


Cucumber
* cucumber exec
* features/*.feature
* features/*.rb




                            62
The Generic Webapp Model


Cucumber               Webapp
* cucumber exec        * web server
* features/*.feature   * deployed app
* features/*.rb        * web browser




                                        63
The Generic Webapp Model


Cucumber                             Webapp
* cucumber exec                      * web server
* features/*.feature                 * deployed files
* features/*.rb                      * web browser

                       Driver
                       * selenium (server+client)



                                                        64
FAST FOWARD
(Completed: Step Definitions)




                                65
Before




After


                 66
Before




After


                 67
Before




After


                 68
Before




After


                 69
Before




After


                 70
A New *.rb File


<PROJECT_ROOT>
 `~ features/
    `- selenium.rb




                     71
72
73
74
75
76
OK, Let's Run It !!




#$ cucumber features




                       77
78
79
Run Selenium Server

    #$ selenium




                      80
Run Selenium Server

    #$ selenium




                      81
82
Let's Try Again

#$ cucumber features




                       83
84
85
The Missing Part ??
~ Our Application ~




                      86
FAST FOWARD AGAIN
(Completed: Application)




                           87
Let's Run the Webapp

    #$ ruby app.rb




                       88
Let's Run the Webapp

    #$ ruby app.rb




                       89
90
Let's Try Once Again

#$ cucumber features




                       91
Let's Try Once Again

#$ cucumber features




                       92
Revision Time




                93
Summing Up
1) Capturing user's requirements
   in a feature file




                                   94
Feature's Title




                  95
Feature's Narrative




                      96
Feature's Narrative




                      97
Feature's Narrative




                      98
Feature's Narrative




                      99
Feature's Acceptance Criterion




                                 100
Feature's Acceptance Criterion




                                 101
Feature's Acceptance Criterion




                                 102
Summing Up
1) Capturing user's requirements
   in a feature file
2) Complete the missing step
   defintions




                                   103
Step Definitions




                   104
Summing Up
1) Capturing user's requirements
   in a feature file
2) Complete the missing step
    defintions
3) Implement the application



                                   105
Useful Links

* Cucumber's Wiki
 http://wiki.github.com/aslakhellesoy/cucumber

* Cucumber's Homepage
 http://cukes.info/

* BDD @ Wikipedia


                                             106
Recommended Video




                    107
THE END




          108

The LAZY Developer's Guide to BDD (with Cucumber)