SlideShare a Scribd company logo
1 of 154
Getting Comfortable with
    Behavior Driven
      Development
          Alex Sharp
        FrothLogic, Inc.
        ajsharp@frothlogic.com
       http://twitter.com/ajsharp
Speaking of “getting
  comfortable”...
I hope you get as comfortable
 with BDD as this guy is with
    EVERYTHING. Boom.
Why are you laughing?
Ok, but seriously.
Let’s talk about...

• Things we’ll cover in this talk:
  1. What is BDD?
  2. Why you should care
  3. How to start doing BDD with cucumber
So, what is BDD?
• Behavior Driven Development (BDD) is a
  software development methodology that
  takes an outside-in approach to describe
  application behavior by encouraging intense
  customer involvement
• Don’t worry, we’ll take this explanation
  from textbook to tolerable over the next
  20-ish minutes...
So, what is BDD?

• BDD borrows it’s core concepts,
  workflow and principles from it’s
  predecessor, Test Driven Development
In fact...
In fact...

• BDD builds on top of Test Driven
  Development (TDD)
In fact...

• BDD builds on top of Test Driven
  Development (TDD)
 • Which begs the question...
Well then what’s TDD?!
Well then what’s TDD?!

 • TDD == Write tests first, production
   code second
Well then what’s TDD?!

 • TDD == Write tests first, production
   code second
    • You’re TAFT, right!?
Well then what’s TDD?!

 • TDD == Write tests first, production
   code second
     • You’re TAFT, right!?
 • Main idea: Use test code to drive
   production code
Well then what’s TDD?!

 • TDD == Write tests first, production
   code second
     • You’re TAFT, right!?
 • Main idea: Use test code to drive
   production code
   • More on this later...
Well then what’s TDD?!


  • TDD/BDD Workflow
   • Red, Green, Refactor
Well then what’s TDD?!
                  Not
                     e:Ye
                            llow
                                   text
                                          has
                                              absol
                                                      utel
                                                          y   no r
                                                                  eleva
                                                                          nce
  •   TDD/BDD Workflow                                                         here.


      • Red, Green, Refactor
Well then what’s TDD?!
Well then what’s TDD?!
  •   TDD/BDD Workflow
Well then what’s TDD?!
  •   TDD/BDD Workflow
      •   Red, Green, Refactor
Well then what’s TDD?!
  •   TDD/BDD Workflow
      •   Red, Green, Refactor
           1. Write a failing test
Well then what’s TDD?!
  •   TDD/BDD Workflow
      •   Red, Green, Refactor
           1. Write a failing test
           2. Write the smallest amount of production
              code possible to get that test to pass
Well then what’s TDD?!
  •   TDD/BDD Workflow
      •   Red, Green, Refactor
           1. Write a failing test
           2. Write the smallest amount of production
              code possible to get that test to pass
           3. Refactor
Well then what’s TDD?!
  •   TDD/BDD Workflow
      •   Red, Green, Refactor
           1. Write a failing test
           2. Write the smallest amount of production
              code possible to get that test to pass
           3. Refactor
               • i.e. add more tests and write better
                  production code
Whoops, we forgot a
      step.
THINK, MAN, THINK!




Don’t forget to think!!
THINK, MAN, THINK!
THINK, MAN, THINK!

 • The real TDD/BDD Workflow
THINK, MAN, THINK!

 • The real TDD/BDD Workflow
  • THINK, Red, Green, Refactor
THINK, MAN, THINK!

 • The real TDD/BDD Workflow
  • THINK, Red, Green, Refactor
  • Thinking is like, really important
THINK, MAN, THINK!

 • The real TDD/BDD Workflow
  • THINK, Red, Green, Refactor
  • Thinking is like, really important
  • It’s easy to forget to think when you
     can just start hacking L337 c0D3Z
THINK, MAN, THINK!

 • The real TDD/BDD Workflow
  • THINK, Red, Green, Refactor
  • Thinking is like, really important
  • It’s easy to forget to think when you
     can just start hacking L337 c0D3Z
THINK, MAN, THINK!
                         k !!
                     h in
                    t
             t to
           ge
   n ’t
        for     • The real TDD/BDD Workflow
D o
                 • THINK, Red, Green, Refactor
                 • Thinking is like, really important
                 • It’s easy to forget to think when you
                        can just start hacking L337 c0D3Z
THINK, MAN, THINK!
                         k !!
                     h in
                    t
             t to
           ge
   n ’t
        for     • The real TDD/BDD Workflow
D o
                 • THINK, Red, Green, Refactor
                 • Thinking is like, really important
                 • It’s easy to forget to think when you
                        can just start hacking L337 c0D3Z
Problem: Thinking is
      HARD.
Problem: Thinking is
        HARD.

• Unfortunately, TDD, and the nature of
  traditional TDD tools often make it harder
  to think about what you’re trying to do.
BDD Picks up where
  TDD leaves off
BDD Picks up where
   TDD leaves off
• TDD defines a really awesome workflow
  (think, red, green, refactor)
BDD Picks up where
   TDD leaves off
• TDD defines a really awesome workflow
  (think, red, green, refactor)
• BDD crystallizes some of the things that
  TDD leaves unclear or undefined.
BDD Picks up where
   TDD leaves off
• TDD defines a really awesome workflow
  (think, red, green, refactor)
• BDD crystallizes some of the things that
  TDD leaves unclear or undefined.
    • BDD == TDD 2.0
BDD Picks up where
   TDD leaves off
• TDD defines a really awesome workflow
  (think, red, green, refactor)
• BDD crystallizes some of the things that
  TDD leaves unclear or undefined.
    • BDD == TDD 2.0
• BDD bridges the gap between specs/
  requirements and actual implementation
BDD Picks up where
  TDD leaves off
BDD Picks up where
   TDD leaves off
• Programmer goals and priorities are more
  clearly aligned with requirements
BDD Picks up where
   TDD leaves off
• Programmer goals and priorities are more
  clearly aligned with requirements
• Why??
BDD Picks up where
   TDD leaves off
• Programmer goals and priorities are more
  clearly aligned with requirements
• Why??
• BDD is implemented in business language
  not programmer pig latin
Programmer pig latin
Programmer pig latin

• 01010000 01110010 01101111 01100111
  01110010 01100001 01101101 01101101
  01100101 01110010 00100000 01110000
  01101001 01100111 00100000 01101100
  01100001 01110100 01101001 01101110
Come to think of it...
Come to think of it...
• In doing this whole TDD/BDD thing, what
  exactly are we trying to do?
Come to think of it...
• In doing this whole TDD/BDD thing, what
  exactly are we trying to do?
   • Test code?
Come to think of it...
• In doing this whole TDD/BDD thing, what
  exactly are we trying to do?
   • Test code?
   • Describe behavior?
Come to think of it...
• In doing this whole TDD/BDD thing, what
  exactly are we trying to do?
   • Test code?
   • Describe behavior?
   • Bill hours?
Come to think of it...
• In doing this whole TDD/BDD thing, what
  exactly are we trying to do?
   • Test code?
   • Describe behavior?
   • Bill hours?
   • Bawl like ca$h money millionaires?
Come to think of it...
• In doing this whole TDD/BDD thing, what
  exactly are we trying to do?
   • Test code?
   • Describe behavior?
   • Bill hours?
   • Bawl like ca$h money millionaires?
Come to think of it...
Come to think of it...
• In doing this whole TDD/BDD thing, what
  are we “trying to do?”
   • Test code?
   • Describe behavior?
   • Bill hours?
   • Bawl like ca$h money millionaires?
Come to think of it...
• In doing this whole TDD/BDD thing, what
  are we “trying to do?”
                             How bout both,
   • Test code?            AT THE SAME TIME!?
   • Describe behavior?
   • Bill hours?
   • Bawl like ca$h money millionaires?
Come to think of it...
• In doing this whole TDD/BDD thing, what
  are we “trying to do?”
                             How bout both,
   • Test code?            AT THE SAME TIME!?
   • Describe behavior?
   • Bill hours?
   • Bawl like ca$h money millionaires?
Come to think of it...
• In doing this whole TDD/BDD thing, what
  are we “trying to do?”
                             How bout both,
   • Test code?            AT THE SAME TIME!?
   • Describe behavior?
   • Bill hours?
   • Bawl like ca$h money millionaires?
Double-whammy
Double-whammy
•   We can describe the behavior we want first,
    and through that process, we drill down into
    lower level unit and functional tests for our
    code.
Double-whammy
•   We can describe the behavior we want first,
    and through that process, we drill down into
    lower level unit and functional tests for our
    code.
     •   What’s the point of testing code before we
         pin down what that code should do?
Double-whammy
•   We can describe the behavior we want first,
    and through that process, we drill down into
    lower level unit and functional tests for our
    code.
     •   What’s the point of testing code before we
         pin down what that code should do?
          •   In other words, we need to define the
              behavior we want/expect before we
              go about testing it.
Dig deeper: What’s the goal of
       “testing” code?

• Is it to test code or describe behavior?? Both.
• TDD is about ensuring behavior.
• BDD is about describing behavior.
    • First we describe the behavior, then we
      ensure that behavior works as expected.
The Fallacy of TDD
The Fallacy of TDD
• Simply writing tests doesn’t necessarily
  yield any value
The Fallacy of TDD
• Simply writing tests doesn’t necessarily
  yield any value
    •   assert_equal(1, 1) # == true
The Fallacy of TDD
• Simply writing tests doesn’t necessarily
  yield any value
    •   assert_equal(1, 1) # == true


• To be useful, our tests must have meaning,
  and that requires:
The Fallacy of TDD
• Simply writing tests doesn’t necessarily
  yield any value
    •   assert_equal(1, 1) # == true


• To be useful, our tests must have meaning,
  and that requires:
    1. Listening to our customers.
The Fallacy of TDD
• Simply writing tests doesn’t necessarily
  yield any value
    •   assert_equal(1, 1) # == true


• To be useful, our tests must have meaning,
  and that requires:
    1. Listening to our customers.
    2. Thinking. Hard.
Problems with TDD
Problems with TDD
Problems with TDD
1. Unit and functional tests are exclusive
   to the “programmer domain”
Problems with TDD
1. Unit and functional tests are exclusive
   to the “programmer domain”
   •   Bad for agile because we lose the
       customer-centric nature of agile at
       this point in the process
Problems with TDD
1. Unit and functional tests are exclusive
   to the “programmer domain”
   •   Bad for agile because we lose the
       customer-centric nature of agile at
       this point in the process
   •   Agile encourages deep customer
       involvement and interaction (as
       opposed to pre-defined
       requirements gathering phase)
Problems with TDD
1. Unit and functional tests are exclusive
   to the “programmer domain”
   •   Bad for agile because we lose the
       customer-centric nature of agile at
       this point in the process
   •   Agile encourages deep customer
       involvement and interaction (as
       opposed to pre-defined
       requirements gathering phase)
         •   This breaks down when
             programmers start writing
             tests in programmer
             language
Problems with TDD
Problems with TDD
2. TDD tends to be associated with isolated tests
Problems with TDD
2. TDD tends to be associated with isolated tests
  •   Unit and functional tests as opposed to integration tests
Problems with TDD
2. TDD tends to be associated with isolated tests
  •   Unit and functional tests as opposed to integration tests
  •   This is both good and bad (mostly bad though)
Problems with TDD
2. TDD tends to be associated with isolated tests
  •   Unit and functional tests as opposed to integration tests
  •   This is both good and bad (mostly bad though)
  •   Good:
Problems with TDD
2. TDD tends to be associated with isolated tests
  •   Unit and functional tests as opposed to integration tests
  •   This is both good and bad (mostly bad though)
  •   Good:
        •   Tests run faster
Problems with TDD
2. TDD tends to be associated with isolated tests
  •   Unit and functional tests as opposed to integration tests
  •   This is both good and bad (mostly bad though)
  •   Good:
        •   Tests run faster
        •   Tests are less brittle because not dependent on other
            parts of app
Problems with TDD
2. TDD tends to be associated with isolated tests
  •   Unit and functional tests as opposed to integration tests
  •   This is both good and bad (mostly bad though)
  •   Good:
        •   Tests run faster
        •   Tests are less brittle because not dependent on other
            parts of app
              •   Rarely the case with web apps
Problems with TDD
2. TDD tends to be associated with isolated tests
  •   Unit and functional tests as opposed to integration tests
  •   This is both good and bad (mostly bad though)
  •   Good:
        •    Tests run faster
        •    Tests are less brittle because not dependent on other
             parts of app
              •   Rarely the case with web apps
  •   Bad:
Problems with TDD
2. TDD tends to be associated with isolated tests
  •   Unit and functional tests as opposed to integration tests
  •   This is both good and bad (mostly bad though)
  •   Good:
        •    Tests run faster
        •    Tests are less brittle because not dependent on other
             parts of app
              •   Rarely the case with web apps
  •   Bad:
        •    Tests become brittle due to excessive state setup (see
             next slide)
Problems with TDD
Problems with TDD
3. Writing isolated tests can feel contrived
   (again, especially in web apps), which often
   produces crappy test code, which results in
   crappier production code
Problems with TDD
3. Writing isolated tests can feel contrived
   (again, especially in web apps), which often
   produces crappy test code, which results in
   crappier production code
    • Typically happens when we have
      complex state setup (like a web app)
Problems with TDD
3. Writing isolated tests can feel contrived
   (again, especially in web apps), which often
   produces crappy test code, which results in
   crappier production code
    • Typically happens when we have
      complex state setup (like a web app)
    • Secondary problem: This “contrived-
      ness” pushes devs away from testing
      altogether, which is even worse.
Problems with TDD
Problems with TDD
4. A lot gets lost in translation due to these
   problems
Problems with TDD
4. A lot gets lost in translation due to these
   problems
    • Trying to translate customer
       conversations into test code is hard as it is
Problems with TDD
4. A lot gets lost in translation due to these
   problems
    • Trying to translate customer
       conversations into test code is hard as it is
    • Trying to overcome the frustration of
       writing seemingly contrived test cases
       makes it even harder
Problems with TDD
4. A lot gets lost in translation due to these
   problems
    • Trying to translate customer
       conversations into test code is hard as it is
    • Trying to overcome the frustration of
       writing seemingly contrived test cases
       makes it even harder
    • Frustration from testing leads to loss of
       focus and decreased productivity
Fear not, there is a
    better way
BDD
BDD
•   BDD takes an outside-in approach
BDD
•   BDD takes an outside-in approach
     •   Starts at the user level, rather than programmer
BDD
•   BDD takes an outside-in approach
      •   Starts at the user level, rather than programmer
•   In short, it’s a different way of thinking about and doing TDD
BDD
•   BDD takes an outside-in approach
      •   Starts at the user level, rather than programmer
•   In short, it’s a different way of thinking about and doing TDD
•   Caveat
BDD
•   BDD takes an outside-in approach
      •   Starts at the user level, rather than programmer
•   In short, it’s a different way of thinking about and doing TDD
•   Caveat
      •   Technically, we could adapt our TDD tools to serve a
          BDD-like role, but we’ll still run into the problems
          just mentioned
Sweet BDD Diagram.
Sweet BDD Diagram.
Sweet BDD Diagram.
       Customer
                  requireme
                            nts
Sweet BDD Diagram.
              Customer
                         requireme
                                   nts




     Custom
           er requi
                   rements
Sweet BDD Diagram.
              Customer
                         requireme
                                   nts




                                 Cu
                                    s
                                   to
                                    me
                                      rr
                                        eq
                                         uir
                                            em
                                             en
                                             ts
     Custom
           er requi
                   rements
Sweet BDD Diagram.
              Customer
                         requireme
                                   nts




                                 Cu
                                    s
                                   to
                                    me
                                      rr
                                        eq
                                                 uir
                                                    em
                                                     en
                                                          ts
                                                                n ts
                                                               e
                                                          em
                                                      quir
                                                 r re
                                              e
                                             m
                                        s to
     Custom                        Cu
           er requi
                   rements
Sweet BDD Diagram.
              Customer
                         requireme
                                   nts




                                 Cu
      BDD (integration tests)




                                    s
                                   to
                                    me
                                      rr
                                        eq
                                                 uir
                                                    em
                                                     en
                                                          ts
                                                                n ts
                                                               e
                                                          em
                                                      quir
                                                 r re
                                              e
                                             m
                                        s to
     Custom                        Cu
            er requi
                    rements
Sweet BDD Diagram.
              Customer
                         requireme
                                   nts




                                 Cu
      BDD (integration tests)




                                    s
                                   to
                                    me
                                      rr
                                        eq
                                                 uir
                                                    em
                                                     en
                                                          ts
                                                                n ts
                                                               e
                                                          em
                                                      quir
      BDD (integration tests)                      re
                                              e  r
                                             m
                                        s to
     Custom                        Cu
            er requi
                    rements
Sweet BDD Diagram.
              Customer
                          requireme
                                    nts




                                  Cu
      BDD (integration tests)




                                     s
                                    to
                                     me
                                       rr
                                         eq
                                                  uir
                                                     em
         TDD (unit/functional




                                                      en
               tests)




                                                           ts
                                                                 n ts
                                                                e
                                                           em
                                                       quir
      BDD (integration tests)                       re
                                               e  r
                                              m
                                         s to
     Custom                         Cu
            er requi
                      rements
Sweet BDD Diagram.
                             Customer
We start at the                          requireme
                                                   nts
outside and drill
down, inwards




                                                 Cu
towards unit and     BDD (integration tests)




                                                    s
                                                   to
functional tests




                                                    me
                                                      rr
                                                        eq
                                                                 uir
                                                                    em
                        TDD (unit/functional




                                                                     en
                              tests)




                                                                          ts
                                                                                n ts
                                                                               e
                                                                          em
                                                                      quir
                     BDD (integration tests)                       re
                                                              e  r
                                                             m
                                                        s to
                    Custom                         Cu
                           er requi
                                     rements
Sweet BDD Diagram.
                                    Customer
       We start at the                          requireme
                                                          nts
       outside and drill
       down, inwards




                                                        Cu
       towards unit and     BDD (integration tests)




                                                           s
                                                          to
       functional tests




                                                           me
                                                             rr
                                                               eq
                                                                        uir
By now you might be




                                                                           em
                               TDD (unit/functional
thinking, “Aren’t




                                                                            en
                                     tests)
these just integration




                                                                                 ts
                                                                                       n ts
tests showed through                                                                  e
                                                                                 em
a totally awesome
                                                                             quir
diagram?”                   BDD (integration tests)                       re
                                                                     e  r
                                                                    m
                                                               s to
                           Custom                         Cu
                                  er requi
                                            rements
Sweet BDD Diagram.
                                    Customer
       We start at the                          requireme
                                                          nts
       outside and drill
       down, inwards




                                                        Cu
       towards unit and     BDD (integration tests)




                                                           s
                                                          to
       functional tests




                                                           me
                                                             rr
                                                               eq
                                                                        uir
By now you might be




                                                                           em
                               TDD (unit/functional
thinking, “Aren’t




                                                                            en
                                     tests)
these just integration




                                                                                 ts
                                                                                       n ts
tests showed through                                                                  e
                                                                                 em
a totally awesome
                                                                             quir
diagram?”                   BDD (integration tests)                       re
                                                                     e  r
                                                                    m
Yes.                                                           s to
                           Custom                         Cu
                                  er requi
                                            rements
Sweet BDD Diagram.
                                    Customer
       We start at the                          requireme
                                                          nts
       outside and drill
       down, inwards




                                                        Cu
       towards unit and     BDD (integration tests)




                                                           s
                                                          to
       functional tests




                                                           me
                                                             rr
                                                               eq
                                                                        uir
By now you might be




                                                                           em
                               TDD (unit/functional
thinking, “Aren’t




                                                                            en
                                     tests)
these just integration




                                                                                 ts
                                                                                       n ts
tests showed through                                                                  e
                                                                                 em
a totally awesome
                                                                             quir
diagram?”                   BDD (integration tests)                       re
                                                                     e  r
                                                                    m
Yes.                                                           s to
                           Custom                         Cu
                                  er requi
                                            rements
Sweet BDD Diagram.
                                    Customer
       We start at the                          requireme
                                                          nts
       outside and drill
       down, inwards




                                                        Cu
       towards unit and     BDD (integration tests)




                                                           s
                                                          to
       functional tests




                                                           me
                                                             rr
                                                               eq
                                                                        uir
By now you might be




                                                                           em
                               TDD (unit/functional
thinking, “Aren’t




                                                                            en
                                     tests)
these just integration




                                                                                 ts
                                                                                       n ts
tests showed through                                                                  e
                                                                                 em
a totally awesome
                                                                             quir
diagram?”                   BDD (integration tests)                       re
                                                                     e  r
                                                                    m
Yes.                                                           s to
                           Custom                         Cu
                                  er requi
                                            rements
Sweet BDD Diagram.
                                    Customer
       We start at the                          requireme
                                                          nts
       outside and drill
       down, inwards




                                                        Cu
       towards unit and     BDD (integration tests)




                                                           s
                                                          to
       functional tests




                                                           me
                                                             rr
                                                               eq
                                                                        uir
By now you might be




                                                                           em
                               TDD (unit/functional
thinking, “Aren’t




                                                                            en
                                     tests)
these just integration




                                                                                 ts
                                                                                       n ts
tests showed through                                                                  e
                                                                                 em
a totally awesome
                                                                             quir
diagram?”                   BDD (integration tests)                       re
                                                                     e  r
                                                                    m
Yes.                                                           s to
                           Custom                         Cu
                                  er requi
                                            rements
Sweet BDD Diagram.
                                    Customer
       We start at the                          requireme
                                                          nts
       outside and drill
       down, inwards




                                                        Cu
       towards unit and     BDD (integration tests)




                                                           s
                                                          to
       functional tests




                                                           me
                                                             rr
                                                               eq
                                                                        uir
By now you might be




                                                                           em
                               TDD (unit/functional
thinking, “Aren’t




                                                                            en
                                     tests)
these just integration




                                                                                 ts
                                                                                       n ts
tests showed through                                                                  e
                                                                                 em
a totally awesome
                                                                             quir
diagram?”                   BDD (integration tests)                       re
                                                                     e  r
                                                                    m
Yes.                                                           s to
                           Custom                         Cu
                                  er requi
                                            rements
Dig deeper: What’s the point of
        testing code?



• Is it to test code or describe behavior??
Dig deeper: What’s the point of
        testing code?



• Is it to test code or describe behavior?? Both.
Workflow

• Describe code with cucumber integration tests
• Use Red, Green, Refactor
• As you go through this process, write unit and
  functional tests along the way
Sample Cucumber Feature
Sample Cucumber Feature
Feature: User login

  Scenario: A registered user attempts to login
    Given I am a registered user with login "ajsharp" and password "secret"
    When I go to the user login page
    And I fill in "Login" with "ajsharp"
    And I fill in "Password" with "secret"
    And I click the "Log In" button
    Then I should be redirected to my profile page
    And I should see "ajsharp's profile"
Sample Cucumber Feature
Sample Cucumber Feature


           BDD Outside-in Workflow
           • Cucumber feature
Sample Cucumber Feature
Feature: User login

  Scenario: A registered user attempts to login
    Given I am a registered user with login "ajsharp" and password "secret"


                                   BDD Outside-in Workflow
                                   • Cucumber feature
Sample Cucumber Feature
Feature: User login

  Scenario: A registered user attempts to login
    Given I am a registered user with login "ajsharp" and password "secret"


                                   BDD Outside-in Workflow
                                   • Cucumber feature
Sample Cucumber Feature
Feature: User login

  Scenario: A registered user attempts to login
    Given I am a registered user with login "ajsharp" and password "secret"


                                   BDD Outside-in Workflow
                                   • Cucumber feature
Sample Cucumber Feature
 Feature: User login

    Scenario: A registered user attempts to login
      Given I am a registered user with login "ajsharp" and password "secret"


                                           BDD Outside-in Workflow
                                           • Cucumber feature


From here, cucumber looks “step definition” files that match (via
    regular expressions -- shout out Perl) the statements in
                       your .feature file.
Sample Cucumber Feature


                                           BDD Outside-in Workflow
                                           • Cucumber feature


From here, cucumber looks “step definition” files that match (via
    regular expressions -- shout out Perl) the statements in
                       your .feature file.
Sample Cucumber Feature


                                            BDD Outside-in Workflow
                                            • Cucumber feature


 From here, cucumber looks “step definition” files that match (via
     regular expressions -- shout out Perl) the statements in
                        your .feature file.


Next Step: Write a failing test
Cucumber step definition file
Cucumber step definition file



             BDD Outside-in Workflow
             • Cucumber feature
                • Step Definition
Cucumber step definition file

Given /^I am a registered user with username "(.+)" and password "(.+)"$/ do |login, pass|
  @user = User.create!(:username => login, :password => pass)
end


                                              BDD Outside-in Workflow
                                              • Cucumber feature
                                                 • Step Definition
Cucumber step definition file

Given /^I am a registered user with username "(.+)" and password "(.+)"$/ do |login, pass|
  @user = User.create!(:username => login, :password => pass)
end


                                               BDD Outside-in Workflow
                                               • Cucumber feature
                                                  • Step Definition


We haven’t implemented the User model yet, so let’s do that....
Cucumber step definition file

Given /^I am a registered user with username "(.+)" and password "(.+)"$/ do |login, pass|
  @user = User.create!(:username => login, :password => pass)
end


                                              BDD Outside-in Workflow
                                              • Cucumber feature
                                                 • Step Definition


We haven’t implemented the User model yet, so let’s do that....
But wait!! To implement the User model, we need to write some
unit tests for it....Red, Green, Refactor
Cucumber step definition file

Given /^I am a registered user with username "(.+)" and password "(.+)"$/ do |login, pass|
  @user = User.create!(:username => login, :password => pass)
end


                                              BDD Outside-in Workflow
                                              • Cucumber feature
                                                 • Step Definition


We haven’t implemented the User model yet, so let’s do that....
But wait!! To implement the User model, we need to write some
unit tests for it....Red, Green, Refactor


Next Step: Green - To make the cucumber step pass (higher level, more outside) we need to
do Red - write failing tests for user model (lower level, more inside)
User Model Unit Test
(or spec, in this case)
User Model Unit Test
                     (or spec, in this case)
describe User do
  it { should validate_presence_of :username }
  it { should validate_presence_of :password }
end
User Model Unit Test
                     (or spec, in this case)
describe User do                                 BDD Outside-in Workflow
  it { should validate_presence_of :username }
  it { should validate_presence_of :password }   • Cucumber feature
end                                                 • Step Definition
                                                       • User model unit test/spec
User Model Unit Test
                     (or spec, in this case)
describe User do                                 BDD Outside-in Workflow
  it { should validate_presence_of :username }
  it { should validate_presence_of :password }   • Cucumber feature
end                                                 • Step Definition
                                                       • User model unit test/spec
User Model Unit Test
                     (or spec, in this case)
describe User do                                 BDD Outside-in Workflow
  it { should validate_presence_of :username }
  it { should validate_presence_of :password }   • Cucumber feature
end                                                 • Step Definition
                                                       • User model unit test/spec


        This will fail, because we haven’t written any production code yet
User Model Unit Test
                      (or spec, in this case)
 describe User do                                 BDD Outside-in Workflow
   it { should validate_presence_of :username }
   it { should validate_presence_of :password }   • Cucumber feature
 end                                                 • Step Definition
                                                        • User model unit test/spec


         This will fail, because we haven’t written any production code yet




Next Step: Green - Make our model unit tests
pass by writing some production code
User Model Unit Test
                    (or spec, in this case)
class User < ActiveRecord::Base
  validates_presence_of :username
  validates_presence_of :password
end
User Model Unit Test
                    (or spec, in this case)
class User < ActiveRecord::Base
  validates_presence_of :username   BDD Outside-in Workflow
  validates_presence_of :password
end                                 • Cucumber feature
                                       • Step Definition
                                          • User model unit test/spec
                                             • User model production code
User Model Unit Test
                    (or spec, in this case)
class User < ActiveRecord::Base
  validates_presence_of :username   BDD Outside-in Workflow
  validates_presence_of :password
end                                 • Cucumber feature
                                       • Step Definition
                                          • User model unit test/spec
                                             • User model production code
User Model Unit Test
                    (or spec, in this case)
class User < ActiveRecord::Base
  validates_presence_of :username                  BDD Outside-in Workflow
  validates_presence_of :password
end                                                • Cucumber feature
                                                      • Step Definition
                                                         • User model unit test/spec
                                                            • User model production code


       This will make our unit tests pass. Nice.
User Model Unit Test
                      (or spec, in this case)
  class User < ActiveRecord::Base
    validates_presence_of :username                  BDD Outside-in Workflow
    validates_presence_of :password
  end                                                • Cucumber feature
                                                        • Step Definition
                                                           • User model unit test/spec
                                                              • User model production code


         This will make our unit tests pass. Nice.




“Bubble up” back to the cucumber .feature as our
unit/functional tests pass
Awesome workflow

• This workflow keeps us focused on building
  business value in our code for our
  customers
   • i.e. customer requirements
Resources
•   BDD
     •   http://behaviour-driven.org/
•   Cucumber
     •   http://cukes.info
     •   http://github.com/aslakhellesoy/cucumber
•   Rspec Beta Book
     •   http://pragprog.com/titles/achbd/the-rspec-
         book
Resources
•   My Blog
     •   http://alexjsharp.com
     •   I’ll post these slides there
•   My github account
     •   http://github.com/ajsharp
•   Questions?
     •   ajsharp@frothlogic.com

More Related Content

What's hot

Behavior Driven Development Pros and Cons
Behavior Driven Development Pros and ConsBehavior Driven Development Pros and Cons
Behavior Driven Development Pros and ConsIosif Itkin
 
Scrum + Behavior Driven Development (BDD) - Colombo
Scrum + Behavior Driven Development (BDD) - ColomboScrum + Behavior Driven Development (BDD) - Colombo
Scrum + Behavior Driven Development (BDD) - ColomboNaveen Kumar Singh
 
Designing with tests
Designing with testsDesigning with tests
Designing with testsDror Helper
 
Introduction to BDD
Introduction to BDDIntroduction to BDD
Introduction to BDDKnoldus Inc.
 
Code quality as a built-in process
Code quality as a built-in processCode quality as a built-in process
Code quality as a built-in processElad Maimon
 
Don't let your tests slow you down
Don't let your tests slow you downDon't let your tests slow you down
Don't let your tests slow you downDaniel Irvine
 
Behavior Driven Development (BDD)
Behavior Driven Development (BDD)Behavior Driven Development (BDD)
Behavior Driven Development (BDD)Ajay Danait
 
Topic tdd-and-bdd b4usolution
Topic tdd-and-bdd b4usolutionTopic tdd-and-bdd b4usolution
Topic tdd-and-bdd b4usolutionHoa Le
 
Behavior Driven Development with AngularJS & Jasmine
Behavior Driven Development with AngularJS & JasmineBehavior Driven Development with AngularJS & Jasmine
Behavior Driven Development with AngularJS & JasmineRemus Langu
 
TDD and BDD in Sky Deutschland
TDD and BDD in Sky DeutschlandTDD and BDD in Sky Deutschland
TDD and BDD in Sky DeutschlandMurphy Meng
 

What's hot (20)

Behavior Driven Development Pros and Cons
Behavior Driven Development Pros and ConsBehavior Driven Development Pros and Cons
Behavior Driven Development Pros and Cons
 
BDD with JBehave
BDD with JBehaveBDD with JBehave
BDD with JBehave
 
BDD-Driven Microservices
BDD-Driven MicroservicesBDD-Driven Microservices
BDD-Driven Microservices
 
Scrum + Behavior Driven Development (BDD) - Colombo
Scrum + Behavior Driven Development (BDD) - ColomboScrum + Behavior Driven Development (BDD) - Colombo
Scrum + Behavior Driven Development (BDD) - Colombo
 
Its testing-jim-but-not-as-we-know-it-devoxx
Its testing-jim-but-not-as-we-know-it-devoxxIts testing-jim-but-not-as-we-know-it-devoxx
Its testing-jim-but-not-as-we-know-it-devoxx
 
Gateway to Agile: XP and BDD
Gateway to Agile: XP and BDD Gateway to Agile: XP and BDD
Gateway to Agile: XP and BDD
 
BDD: The unit test of the product owner
BDD: The unit test of the product ownerBDD: The unit test of the product owner
BDD: The unit test of the product owner
 
BDD & Cucumber
BDD & CucumberBDD & Cucumber
BDD & Cucumber
 
Designing with tests
Designing with testsDesigning with tests
Designing with tests
 
Bdd Introduction
Bdd IntroductionBdd Introduction
Bdd Introduction
 
Introduction to BDD
Introduction to BDDIntroduction to BDD
Introduction to BDD
 
Code quality as a built-in process
Code quality as a built-in processCode quality as a built-in process
Code quality as a built-in process
 
BDD in Action - Devoxx 2014
BDD in Action - Devoxx 2014BDD in Action - Devoxx 2014
BDD in Action - Devoxx 2014
 
BDD Anti-patterns
BDD Anti-patternsBDD Anti-patterns
BDD Anti-patterns
 
Don't let your tests slow you down
Don't let your tests slow you downDon't let your tests slow you down
Don't let your tests slow you down
 
Behavior Driven Development (BDD)
Behavior Driven Development (BDD)Behavior Driven Development (BDD)
Behavior Driven Development (BDD)
 
Topic tdd-and-bdd b4usolution
Topic tdd-and-bdd b4usolutionTopic tdd-and-bdd b4usolution
Topic tdd-and-bdd b4usolution
 
Behavior Driven Development with AngularJS & Jasmine
Behavior Driven Development with AngularJS & JasmineBehavior Driven Development with AngularJS & Jasmine
Behavior Driven Development with AngularJS & Jasmine
 
TDD and BDD in Sky Deutschland
TDD and BDD in Sky DeutschlandTDD and BDD in Sky Deutschland
TDD and BDD in Sky Deutschland
 
Atdd half day_new_1_up
Atdd half day_new_1_upAtdd half day_new_1_up
Atdd half day_new_1_up
 

Viewers also liked

The WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecThe WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecBen Mabey
 
BDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world applicationBDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world applicationJohn Ferguson Smart Limited
 
BDD - Writing better scenario
BDD - Writing better scenarioBDD - Writing better scenario
BDD - Writing better scenarioArnauld Loyer
 
An introduction to Behavior-Driven Development (BDD)
An introduction to Behavior-Driven Development (BDD)An introduction to Behavior-Driven Development (BDD)
An introduction to Behavior-Driven Development (BDD)Suman Guha
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testingdversaci
 
BDD with JBehave and Selenium
BDD with JBehave and SeleniumBDD with JBehave and Selenium
BDD with JBehave and SeleniumNikolay Vasilev
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven DevelopmentLiz Keogh
 
BDD & Rspec
BDD & Rspec BDD & Rspec
BDD & Rspec Robbert
 
BDD / Specification by example
BDD / Specification by exampleBDD / Specification by example
BDD / Specification by examplemgiota
 
Behavior Driven Development: An Overview
Behavior Driven Development:  An OverviewBehavior Driven Development:  An Overview
Behavior Driven Development: An Overviewbmaynard_at_litle
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMarakana Inc.
 
BDD: What's in it for me?
BDD: What's in it for me?BDD: What's in it for me?
BDD: What's in it for me?fuglylogic
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven DevelopmentMarakana Inc.
 
Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteGiordano Scalzo
 

Viewers also liked (20)

The WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecThe WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpec
 
BDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world applicationBDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world application
 
BDD - Writing better scenario
BDD - Writing better scenarioBDD - Writing better scenario
BDD - Writing better scenario
 
An introduction to Behavior-Driven Development (BDD)
An introduction to Behavior-Driven Development (BDD)An introduction to Behavior-Driven Development (BDD)
An introduction to Behavior-Driven Development (BDD)
 
BDD - Collaborate like you mean it!
BDD - Collaborate like you mean it!BDD - Collaborate like you mean it!
BDD - Collaborate like you mean it!
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testing
 
BDD with JBehave and Selenium
BDD with JBehave and SeleniumBDD with JBehave and Selenium
BDD with JBehave and Selenium
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
 
BDD & Behat
BDD & BehatBDD & Behat
BDD & Behat
 
BDD & Rspec
BDD & Rspec BDD & Rspec
BDD & Rspec
 
BDD / Specification by example
BDD / Specification by exampleBDD / Specification by example
BDD / Specification by example
 
BDD by example
BDD by exampleBDD by example
BDD by example
 
Behavior Driven Development: An Overview
Behavior Driven Development:  An OverviewBehavior Driven Development:  An Overview
Behavior Driven Development: An Overview
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for Scala
 
BDD: What's in it for me?
BDD: What's in it for me?BDD: What's in it for me?
BDD: What's in it for me?
 
BDD: There's more to it than you think
BDD: There's more to it than you thinkBDD: There's more to it than you think
BDD: There's more to it than you think
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
 
Bdd and Scrum Team Dynamics
Bdd and Scrum Team DynamicsBdd and Scrum Team Dynamics
Bdd and Scrum Team Dynamics
 
TDD & BDD
TDD & BDDTDD & BDD
TDD & BDD
 
Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infinite
 

Similar to Getting Comfortable with BDD

Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is ImportaintSana Nasar
 
WeActuallyBuildStuff - Extreme Programming Live
WeActuallyBuildStuff - Extreme Programming LiveWeActuallyBuildStuff - Extreme Programming Live
WeActuallyBuildStuff - Extreme Programming LiveJohannes Brodwall
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-testsSkills Matter
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-testsSkills Matter
 
I'm a TDD cheat and I'm not afraid to admit it
I'm a TDD cheat and I'm not afraid to admit itI'm a TDD cheat and I'm not afraid to admit it
I'm a TDD cheat and I'm not afraid to admit itDaniel Irvine
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Jason Tice
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Danny Preussler
 
TDD: seriously, try it! 
TDD: seriously, try it! TDD: seriously, try it! 
TDD: seriously, try it! Nacho Cougil
 
TDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereTDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereDaniel Davis
 
Test Driven Development SpeedRun
Test Driven Development SpeedRunTest Driven Development SpeedRun
Test Driven Development SpeedRunSpeck&Tech
 
Coding Dojo Firenze - vol1
Coding Dojo Firenze - vol1 Coding Dojo Firenze - vol1
Coding Dojo Firenze - vol1 Massimo Iacolare
 
Living Documentation (NCrafts Paris 2015, DDDx London 2015, BDX.io 2015, Code...
Living Documentation (NCrafts Paris 2015, DDDx London 2015, BDX.io 2015, Code...Living Documentation (NCrafts Paris 2015, DDDx London 2015, BDX.io 2015, Code...
Living Documentation (NCrafts Paris 2015, DDDx London 2015, BDX.io 2015, Code...Cyrille Martraire
 
Successful Project Presentation
Successful Project PresentationSuccessful Project Presentation
Successful Project PresentationColin Sullivan
 
Global Day of Coderetreat Munich 2018
Global Day of Coderetreat Munich 2018Global Day of Coderetreat Munich 2018
Global Day of Coderetreat Munich 2018David Völkel
 
2013 09-11 java zone - extreme programming live
2013 09-11 java zone - extreme programming live2013 09-11 java zone - extreme programming live
2013 09-11 java zone - extreme programming liveJohannes Brodwall
 

Similar to Getting Comfortable with BDD (20)

Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is Importaint
 
WeActuallyBuildStuff - Extreme Programming Live
WeActuallyBuildStuff - Extreme Programming LiveWeActuallyBuildStuff - Extreme Programming Live
WeActuallyBuildStuff - Extreme Programming Live
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-tests
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-tests
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-tests
 
I'm a TDD cheat and I'm not afraid to admit it
I'm a TDD cheat and I'm not afraid to admit itI'm a TDD cheat and I'm not afraid to admit it
I'm a TDD cheat and I'm not afraid to admit it
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
 
Make a better with clean code
Make a better with clean codeMake a better with clean code
Make a better with clean code
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
WTF is TDD
WTF is TDDWTF is TDD
WTF is TDD
 
TDD: seriously, try it! 
TDD: seriously, try it! TDD: seriously, try it! 
TDD: seriously, try it! 
 
Tdd!
Tdd!Tdd!
Tdd!
 
TDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereTDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & Where
 
Test Driven Development SpeedRun
Test Driven Development SpeedRunTest Driven Development SpeedRun
Test Driven Development SpeedRun
 
Tdd and bdd
Tdd and bddTdd and bdd
Tdd and bdd
 
Coding Dojo Firenze - vol1
Coding Dojo Firenze - vol1 Coding Dojo Firenze - vol1
Coding Dojo Firenze - vol1
 
Living Documentation (NCrafts Paris 2015, DDDx London 2015, BDX.io 2015, Code...
Living Documentation (NCrafts Paris 2015, DDDx London 2015, BDX.io 2015, Code...Living Documentation (NCrafts Paris 2015, DDDx London 2015, BDX.io 2015, Code...
Living Documentation (NCrafts Paris 2015, DDDx London 2015, BDX.io 2015, Code...
 
Successful Project Presentation
Successful Project PresentationSuccessful Project Presentation
Successful Project Presentation
 
Global Day of Coderetreat Munich 2018
Global Day of Coderetreat Munich 2018Global Day of Coderetreat Munich 2018
Global Day of Coderetreat Munich 2018
 
2013 09-11 java zone - extreme programming live
2013 09-11 java zone - extreme programming live2013 09-11 java zone - extreme programming live
2013 09-11 java zone - extreme programming live
 

More from Alex Sharp

Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSLBldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSLAlex Sharp
 
Bldr - Rubyconf 2011 Lightning Talk
Bldr - Rubyconf 2011 Lightning TalkBldr - Rubyconf 2011 Lightning Talk
Bldr - Rubyconf 2011 Lightning TalkAlex Sharp
 
Mysql to mongo
Mysql to mongoMysql to mongo
Mysql to mongoAlex Sharp
 
Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010Alex Sharp
 
Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010Alex Sharp
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Alex Sharp
 
Practical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby MidwestPractical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby MidwestAlex Sharp
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFAlex Sharp
 
Practical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbPractical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbAlex Sharp
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDBAlex Sharp
 
Testing Has Many Purposes
Testing Has Many PurposesTesting Has Many Purposes
Testing Has Many PurposesAlex Sharp
 

More from Alex Sharp (11)

Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSLBldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
 
Bldr - Rubyconf 2011 Lightning Talk
Bldr - Rubyconf 2011 Lightning TalkBldr - Rubyconf 2011 Lightning Talk
Bldr - Rubyconf 2011 Lightning Talk
 
Mysql to mongo
Mysql to mongoMysql to mongo
Mysql to mongo
 
Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010
 
Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
 
Practical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby MidwestPractical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby Midwest
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSF
 
Practical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbPractical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo Db
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
 
Testing Has Many Purposes
Testing Has Many PurposesTesting Has Many Purposes
Testing Has Many Purposes
 

Recently uploaded

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Recently uploaded (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 

Getting Comfortable with BDD

  • 1. Getting Comfortable with Behavior Driven Development Alex Sharp FrothLogic, Inc. ajsharp@frothlogic.com http://twitter.com/ajsharp
  • 2. Speaking of “getting comfortable”...
  • 3. I hope you get as comfortable with BDD as this guy is with EVERYTHING. Boom.
  • 4. Why are you laughing?
  • 5.
  • 7.
  • 8. Let’s talk about... • Things we’ll cover in this talk: 1. What is BDD? 2. Why you should care 3. How to start doing BDD with cucumber
  • 9. So, what is BDD? • Behavior Driven Development (BDD) is a software development methodology that takes an outside-in approach to describe application behavior by encouraging intense customer involvement • Don’t worry, we’ll take this explanation from textbook to tolerable over the next 20-ish minutes...
  • 10. So, what is BDD? • BDD borrows it’s core concepts, workflow and principles from it’s predecessor, Test Driven Development
  • 12. In fact... • BDD builds on top of Test Driven Development (TDD)
  • 13. In fact... • BDD builds on top of Test Driven Development (TDD) • Which begs the question...
  • 15. Well then what’s TDD?! • TDD == Write tests first, production code second
  • 16. Well then what’s TDD?! • TDD == Write tests first, production code second • You’re TAFT, right!?
  • 17. Well then what’s TDD?! • TDD == Write tests first, production code second • You’re TAFT, right!? • Main idea: Use test code to drive production code
  • 18. Well then what’s TDD?! • TDD == Write tests first, production code second • You’re TAFT, right!? • Main idea: Use test code to drive production code • More on this later...
  • 19. Well then what’s TDD?! • TDD/BDD Workflow • Red, Green, Refactor
  • 20. Well then what’s TDD?! Not e:Ye llow text has absol utel y no r eleva nce • TDD/BDD Workflow here. • Red, Green, Refactor
  • 22. Well then what’s TDD?! • TDD/BDD Workflow
  • 23. Well then what’s TDD?! • TDD/BDD Workflow • Red, Green, Refactor
  • 24. Well then what’s TDD?! • TDD/BDD Workflow • Red, Green, Refactor 1. Write a failing test
  • 25. Well then what’s TDD?! • TDD/BDD Workflow • Red, Green, Refactor 1. Write a failing test 2. Write the smallest amount of production code possible to get that test to pass
  • 26. Well then what’s TDD?! • TDD/BDD Workflow • Red, Green, Refactor 1. Write a failing test 2. Write the smallest amount of production code possible to get that test to pass 3. Refactor
  • 27. Well then what’s TDD?! • TDD/BDD Workflow • Red, Green, Refactor 1. Write a failing test 2. Write the smallest amount of production code possible to get that test to pass 3. Refactor • i.e. add more tests and write better production code
  • 28. Whoops, we forgot a step.
  • 29. THINK, MAN, THINK! Don’t forget to think!!
  • 31. THINK, MAN, THINK! • The real TDD/BDD Workflow
  • 32. THINK, MAN, THINK! • The real TDD/BDD Workflow • THINK, Red, Green, Refactor
  • 33. THINK, MAN, THINK! • The real TDD/BDD Workflow • THINK, Red, Green, Refactor • Thinking is like, really important
  • 34. THINK, MAN, THINK! • The real TDD/BDD Workflow • THINK, Red, Green, Refactor • Thinking is like, really important • It’s easy to forget to think when you can just start hacking L337 c0D3Z
  • 35. THINK, MAN, THINK! • The real TDD/BDD Workflow • THINK, Red, Green, Refactor • Thinking is like, really important • It’s easy to forget to think when you can just start hacking L337 c0D3Z
  • 36. THINK, MAN, THINK! k !! h in t t to ge n ’t for • The real TDD/BDD Workflow D o • THINK, Red, Green, Refactor • Thinking is like, really important • It’s easy to forget to think when you can just start hacking L337 c0D3Z
  • 37. THINK, MAN, THINK! k !! h in t t to ge n ’t for • The real TDD/BDD Workflow D o • THINK, Red, Green, Refactor • Thinking is like, really important • It’s easy to forget to think when you can just start hacking L337 c0D3Z
  • 39. Problem: Thinking is HARD. • Unfortunately, TDD, and the nature of traditional TDD tools often make it harder to think about what you’re trying to do.
  • 40. BDD Picks up where TDD leaves off
  • 41. BDD Picks up where TDD leaves off • TDD defines a really awesome workflow (think, red, green, refactor)
  • 42. BDD Picks up where TDD leaves off • TDD defines a really awesome workflow (think, red, green, refactor) • BDD crystallizes some of the things that TDD leaves unclear or undefined.
  • 43. BDD Picks up where TDD leaves off • TDD defines a really awesome workflow (think, red, green, refactor) • BDD crystallizes some of the things that TDD leaves unclear or undefined. • BDD == TDD 2.0
  • 44. BDD Picks up where TDD leaves off • TDD defines a really awesome workflow (think, red, green, refactor) • BDD crystallizes some of the things that TDD leaves unclear or undefined. • BDD == TDD 2.0 • BDD bridges the gap between specs/ requirements and actual implementation
  • 45. BDD Picks up where TDD leaves off
  • 46. BDD Picks up where TDD leaves off • Programmer goals and priorities are more clearly aligned with requirements
  • 47. BDD Picks up where TDD leaves off • Programmer goals and priorities are more clearly aligned with requirements • Why??
  • 48. BDD Picks up where TDD leaves off • Programmer goals and priorities are more clearly aligned with requirements • Why?? • BDD is implemented in business language not programmer pig latin
  • 50. Programmer pig latin • 01010000 01110010 01101111 01100111 01110010 01100001 01101101 01101101 01100101 01110010 00100000 01110000 01101001 01100111 00100000 01101100 01100001 01110100 01101001 01101110
  • 51. Come to think of it...
  • 52. Come to think of it... • In doing this whole TDD/BDD thing, what exactly are we trying to do?
  • 53. Come to think of it... • In doing this whole TDD/BDD thing, what exactly are we trying to do? • Test code?
  • 54. Come to think of it... • In doing this whole TDD/BDD thing, what exactly are we trying to do? • Test code? • Describe behavior?
  • 55. Come to think of it... • In doing this whole TDD/BDD thing, what exactly are we trying to do? • Test code? • Describe behavior? • Bill hours?
  • 56. Come to think of it... • In doing this whole TDD/BDD thing, what exactly are we trying to do? • Test code? • Describe behavior? • Bill hours? • Bawl like ca$h money millionaires?
  • 57. Come to think of it... • In doing this whole TDD/BDD thing, what exactly are we trying to do? • Test code? • Describe behavior? • Bill hours? • Bawl like ca$h money millionaires?
  • 58. Come to think of it...
  • 59. Come to think of it... • In doing this whole TDD/BDD thing, what are we “trying to do?” • Test code? • Describe behavior? • Bill hours? • Bawl like ca$h money millionaires?
  • 60. Come to think of it... • In doing this whole TDD/BDD thing, what are we “trying to do?” How bout both, • Test code? AT THE SAME TIME!? • Describe behavior? • Bill hours? • Bawl like ca$h money millionaires?
  • 61. Come to think of it... • In doing this whole TDD/BDD thing, what are we “trying to do?” How bout both, • Test code? AT THE SAME TIME!? • Describe behavior? • Bill hours? • Bawl like ca$h money millionaires?
  • 62. Come to think of it... • In doing this whole TDD/BDD thing, what are we “trying to do?” How bout both, • Test code? AT THE SAME TIME!? • Describe behavior? • Bill hours? • Bawl like ca$h money millionaires?
  • 64. Double-whammy • We can describe the behavior we want first, and through that process, we drill down into lower level unit and functional tests for our code.
  • 65. Double-whammy • We can describe the behavior we want first, and through that process, we drill down into lower level unit and functional tests for our code. • What’s the point of testing code before we pin down what that code should do?
  • 66. Double-whammy • We can describe the behavior we want first, and through that process, we drill down into lower level unit and functional tests for our code. • What’s the point of testing code before we pin down what that code should do? • In other words, we need to define the behavior we want/expect before we go about testing it.
  • 67. Dig deeper: What’s the goal of “testing” code? • Is it to test code or describe behavior?? Both. • TDD is about ensuring behavior. • BDD is about describing behavior. • First we describe the behavior, then we ensure that behavior works as expected.
  • 69. The Fallacy of TDD • Simply writing tests doesn’t necessarily yield any value
  • 70. The Fallacy of TDD • Simply writing tests doesn’t necessarily yield any value • assert_equal(1, 1) # == true
  • 71. The Fallacy of TDD • Simply writing tests doesn’t necessarily yield any value • assert_equal(1, 1) # == true • To be useful, our tests must have meaning, and that requires:
  • 72. The Fallacy of TDD • Simply writing tests doesn’t necessarily yield any value • assert_equal(1, 1) # == true • To be useful, our tests must have meaning, and that requires: 1. Listening to our customers.
  • 73. The Fallacy of TDD • Simply writing tests doesn’t necessarily yield any value • assert_equal(1, 1) # == true • To be useful, our tests must have meaning, and that requires: 1. Listening to our customers. 2. Thinking. Hard.
  • 76. Problems with TDD 1. Unit and functional tests are exclusive to the “programmer domain”
  • 77. Problems with TDD 1. Unit and functional tests are exclusive to the “programmer domain” • Bad for agile because we lose the customer-centric nature of agile at this point in the process
  • 78. Problems with TDD 1. Unit and functional tests are exclusive to the “programmer domain” • Bad for agile because we lose the customer-centric nature of agile at this point in the process • Agile encourages deep customer involvement and interaction (as opposed to pre-defined requirements gathering phase)
  • 79. Problems with TDD 1. Unit and functional tests are exclusive to the “programmer domain” • Bad for agile because we lose the customer-centric nature of agile at this point in the process • Agile encourages deep customer involvement and interaction (as opposed to pre-defined requirements gathering phase) • This breaks down when programmers start writing tests in programmer language
  • 81. Problems with TDD 2. TDD tends to be associated with isolated tests
  • 82. Problems with TDD 2. TDD tends to be associated with isolated tests • Unit and functional tests as opposed to integration tests
  • 83. Problems with TDD 2. TDD tends to be associated with isolated tests • Unit and functional tests as opposed to integration tests • This is both good and bad (mostly bad though)
  • 84. Problems with TDD 2. TDD tends to be associated with isolated tests • Unit and functional tests as opposed to integration tests • This is both good and bad (mostly bad though) • Good:
  • 85. Problems with TDD 2. TDD tends to be associated with isolated tests • Unit and functional tests as opposed to integration tests • This is both good and bad (mostly bad though) • Good: • Tests run faster
  • 86. Problems with TDD 2. TDD tends to be associated with isolated tests • Unit and functional tests as opposed to integration tests • This is both good and bad (mostly bad though) • Good: • Tests run faster • Tests are less brittle because not dependent on other parts of app
  • 87. Problems with TDD 2. TDD tends to be associated with isolated tests • Unit and functional tests as opposed to integration tests • This is both good and bad (mostly bad though) • Good: • Tests run faster • Tests are less brittle because not dependent on other parts of app • Rarely the case with web apps
  • 88. Problems with TDD 2. TDD tends to be associated with isolated tests • Unit and functional tests as opposed to integration tests • This is both good and bad (mostly bad though) • Good: • Tests run faster • Tests are less brittle because not dependent on other parts of app • Rarely the case with web apps • Bad:
  • 89. Problems with TDD 2. TDD tends to be associated with isolated tests • Unit and functional tests as opposed to integration tests • This is both good and bad (mostly bad though) • Good: • Tests run faster • Tests are less brittle because not dependent on other parts of app • Rarely the case with web apps • Bad: • Tests become brittle due to excessive state setup (see next slide)
  • 91. Problems with TDD 3. Writing isolated tests can feel contrived (again, especially in web apps), which often produces crappy test code, which results in crappier production code
  • 92. Problems with TDD 3. Writing isolated tests can feel contrived (again, especially in web apps), which often produces crappy test code, which results in crappier production code • Typically happens when we have complex state setup (like a web app)
  • 93. Problems with TDD 3. Writing isolated tests can feel contrived (again, especially in web apps), which often produces crappy test code, which results in crappier production code • Typically happens when we have complex state setup (like a web app) • Secondary problem: This “contrived- ness” pushes devs away from testing altogether, which is even worse.
  • 95. Problems with TDD 4. A lot gets lost in translation due to these problems
  • 96. Problems with TDD 4. A lot gets lost in translation due to these problems • Trying to translate customer conversations into test code is hard as it is
  • 97. Problems with TDD 4. A lot gets lost in translation due to these problems • Trying to translate customer conversations into test code is hard as it is • Trying to overcome the frustration of writing seemingly contrived test cases makes it even harder
  • 98. Problems with TDD 4. A lot gets lost in translation due to these problems • Trying to translate customer conversations into test code is hard as it is • Trying to overcome the frustration of writing seemingly contrived test cases makes it even harder • Frustration from testing leads to loss of focus and decreased productivity
  • 99. Fear not, there is a better way
  • 100. BDD
  • 101. BDD • BDD takes an outside-in approach
  • 102. BDD • BDD takes an outside-in approach • Starts at the user level, rather than programmer
  • 103. BDD • BDD takes an outside-in approach • Starts at the user level, rather than programmer • In short, it’s a different way of thinking about and doing TDD
  • 104. BDD • BDD takes an outside-in approach • Starts at the user level, rather than programmer • In short, it’s a different way of thinking about and doing TDD • Caveat
  • 105. BDD • BDD takes an outside-in approach • Starts at the user level, rather than programmer • In short, it’s a different way of thinking about and doing TDD • Caveat • Technically, we could adapt our TDD tools to serve a BDD-like role, but we’ll still run into the problems just mentioned
  • 108. Sweet BDD Diagram. Customer requireme nts
  • 109. Sweet BDD Diagram. Customer requireme nts Custom er requi rements
  • 110. Sweet BDD Diagram. Customer requireme nts Cu s to me rr eq uir em en ts Custom er requi rements
  • 111. Sweet BDD Diagram. Customer requireme nts Cu s to me rr eq uir em en ts n ts e em quir r re e m s to Custom Cu er requi rements
  • 112. Sweet BDD Diagram. Customer requireme nts Cu BDD (integration tests) s to me rr eq uir em en ts n ts e em quir r re e m s to Custom Cu er requi rements
  • 113. Sweet BDD Diagram. Customer requireme nts Cu BDD (integration tests) s to me rr eq uir em en ts n ts e em quir BDD (integration tests) re e r m s to Custom Cu er requi rements
  • 114. Sweet BDD Diagram. Customer requireme nts Cu BDD (integration tests) s to me rr eq uir em TDD (unit/functional en tests) ts n ts e em quir BDD (integration tests) re e r m s to Custom Cu er requi rements
  • 115. Sweet BDD Diagram. Customer We start at the requireme nts outside and drill down, inwards Cu towards unit and BDD (integration tests) s to functional tests me rr eq uir em TDD (unit/functional en tests) ts n ts e em quir BDD (integration tests) re e r m s to Custom Cu er requi rements
  • 116. Sweet BDD Diagram. Customer We start at the requireme nts outside and drill down, inwards Cu towards unit and BDD (integration tests) s to functional tests me rr eq uir By now you might be em TDD (unit/functional thinking, “Aren’t en tests) these just integration ts n ts tests showed through e em a totally awesome quir diagram?” BDD (integration tests) re e r m s to Custom Cu er requi rements
  • 117. Sweet BDD Diagram. Customer We start at the requireme nts outside and drill down, inwards Cu towards unit and BDD (integration tests) s to functional tests me rr eq uir By now you might be em TDD (unit/functional thinking, “Aren’t en tests) these just integration ts n ts tests showed through e em a totally awesome quir diagram?” BDD (integration tests) re e r m Yes. s to Custom Cu er requi rements
  • 118. Sweet BDD Diagram. Customer We start at the requireme nts outside and drill down, inwards Cu towards unit and BDD (integration tests) s to functional tests me rr eq uir By now you might be em TDD (unit/functional thinking, “Aren’t en tests) these just integration ts n ts tests showed through e em a totally awesome quir diagram?” BDD (integration tests) re e r m Yes. s to Custom Cu er requi rements
  • 119. Sweet BDD Diagram. Customer We start at the requireme nts outside and drill down, inwards Cu towards unit and BDD (integration tests) s to functional tests me rr eq uir By now you might be em TDD (unit/functional thinking, “Aren’t en tests) these just integration ts n ts tests showed through e em a totally awesome quir diagram?” BDD (integration tests) re e r m Yes. s to Custom Cu er requi rements
  • 120. Sweet BDD Diagram. Customer We start at the requireme nts outside and drill down, inwards Cu towards unit and BDD (integration tests) s to functional tests me rr eq uir By now you might be em TDD (unit/functional thinking, “Aren’t en tests) these just integration ts n ts tests showed through e em a totally awesome quir diagram?” BDD (integration tests) re e r m Yes. s to Custom Cu er requi rements
  • 121. Sweet BDD Diagram. Customer We start at the requireme nts outside and drill down, inwards Cu towards unit and BDD (integration tests) s to functional tests me rr eq uir By now you might be em TDD (unit/functional thinking, “Aren’t en tests) these just integration ts n ts tests showed through e em a totally awesome quir diagram?” BDD (integration tests) re e r m Yes. s to Custom Cu er requi rements
  • 122. Dig deeper: What’s the point of testing code? • Is it to test code or describe behavior??
  • 123. Dig deeper: What’s the point of testing code? • Is it to test code or describe behavior?? Both.
  • 124. Workflow • Describe code with cucumber integration tests • Use Red, Green, Refactor • As you go through this process, write unit and functional tests along the way
  • 126. Sample Cucumber Feature Feature: User login Scenario: A registered user attempts to login Given I am a registered user with login "ajsharp" and password "secret" When I go to the user login page And I fill in "Login" with "ajsharp" And I fill in "Password" with "secret" And I click the "Log In" button Then I should be redirected to my profile page And I should see "ajsharp's profile"
  • 128. Sample Cucumber Feature BDD Outside-in Workflow • Cucumber feature
  • 129. Sample Cucumber Feature Feature: User login Scenario: A registered user attempts to login Given I am a registered user with login "ajsharp" and password "secret" BDD Outside-in Workflow • Cucumber feature
  • 130. Sample Cucumber Feature Feature: User login Scenario: A registered user attempts to login Given I am a registered user with login "ajsharp" and password "secret" BDD Outside-in Workflow • Cucumber feature
  • 131. Sample Cucumber Feature Feature: User login Scenario: A registered user attempts to login Given I am a registered user with login "ajsharp" and password "secret" BDD Outside-in Workflow • Cucumber feature
  • 132. Sample Cucumber Feature Feature: User login Scenario: A registered user attempts to login Given I am a registered user with login "ajsharp" and password "secret" BDD Outside-in Workflow • Cucumber feature From here, cucumber looks “step definition” files that match (via regular expressions -- shout out Perl) the statements in your .feature file.
  • 133. Sample Cucumber Feature BDD Outside-in Workflow • Cucumber feature From here, cucumber looks “step definition” files that match (via regular expressions -- shout out Perl) the statements in your .feature file.
  • 134. Sample Cucumber Feature BDD Outside-in Workflow • Cucumber feature From here, cucumber looks “step definition” files that match (via regular expressions -- shout out Perl) the statements in your .feature file. Next Step: Write a failing test
  • 136. Cucumber step definition file BDD Outside-in Workflow • Cucumber feature • Step Definition
  • 137. Cucumber step definition file Given /^I am a registered user with username "(.+)" and password "(.+)"$/ do |login, pass| @user = User.create!(:username => login, :password => pass) end BDD Outside-in Workflow • Cucumber feature • Step Definition
  • 138. Cucumber step definition file Given /^I am a registered user with username "(.+)" and password "(.+)"$/ do |login, pass| @user = User.create!(:username => login, :password => pass) end BDD Outside-in Workflow • Cucumber feature • Step Definition We haven’t implemented the User model yet, so let’s do that....
  • 139. Cucumber step definition file Given /^I am a registered user with username "(.+)" and password "(.+)"$/ do |login, pass| @user = User.create!(:username => login, :password => pass) end BDD Outside-in Workflow • Cucumber feature • Step Definition We haven’t implemented the User model yet, so let’s do that.... But wait!! To implement the User model, we need to write some unit tests for it....Red, Green, Refactor
  • 140. Cucumber step definition file Given /^I am a registered user with username "(.+)" and password "(.+)"$/ do |login, pass| @user = User.create!(:username => login, :password => pass) end BDD Outside-in Workflow • Cucumber feature • Step Definition We haven’t implemented the User model yet, so let’s do that.... But wait!! To implement the User model, we need to write some unit tests for it....Red, Green, Refactor Next Step: Green - To make the cucumber step pass (higher level, more outside) we need to do Red - write failing tests for user model (lower level, more inside)
  • 141. User Model Unit Test (or spec, in this case)
  • 142. User Model Unit Test (or spec, in this case) describe User do it { should validate_presence_of :username } it { should validate_presence_of :password } end
  • 143. User Model Unit Test (or spec, in this case) describe User do BDD Outside-in Workflow it { should validate_presence_of :username } it { should validate_presence_of :password } • Cucumber feature end • Step Definition • User model unit test/spec
  • 144. User Model Unit Test (or spec, in this case) describe User do BDD Outside-in Workflow it { should validate_presence_of :username } it { should validate_presence_of :password } • Cucumber feature end • Step Definition • User model unit test/spec
  • 145. User Model Unit Test (or spec, in this case) describe User do BDD Outside-in Workflow it { should validate_presence_of :username } it { should validate_presence_of :password } • Cucumber feature end • Step Definition • User model unit test/spec This will fail, because we haven’t written any production code yet
  • 146. User Model Unit Test (or spec, in this case) describe User do BDD Outside-in Workflow it { should validate_presence_of :username } it { should validate_presence_of :password } • Cucumber feature end • Step Definition • User model unit test/spec This will fail, because we haven’t written any production code yet Next Step: Green - Make our model unit tests pass by writing some production code
  • 147. User Model Unit Test (or spec, in this case) class User < ActiveRecord::Base validates_presence_of :username validates_presence_of :password end
  • 148. User Model Unit Test (or spec, in this case) class User < ActiveRecord::Base validates_presence_of :username BDD Outside-in Workflow validates_presence_of :password end • Cucumber feature • Step Definition • User model unit test/spec • User model production code
  • 149. User Model Unit Test (or spec, in this case) class User < ActiveRecord::Base validates_presence_of :username BDD Outside-in Workflow validates_presence_of :password end • Cucumber feature • Step Definition • User model unit test/spec • User model production code
  • 150. User Model Unit Test (or spec, in this case) class User < ActiveRecord::Base validates_presence_of :username BDD Outside-in Workflow validates_presence_of :password end • Cucumber feature • Step Definition • User model unit test/spec • User model production code This will make our unit tests pass. Nice.
  • 151. User Model Unit Test (or spec, in this case) class User < ActiveRecord::Base validates_presence_of :username BDD Outside-in Workflow validates_presence_of :password end • Cucumber feature • Step Definition • User model unit test/spec • User model production code This will make our unit tests pass. Nice. “Bubble up” back to the cucumber .feature as our unit/functional tests pass
  • 152. Awesome workflow • This workflow keeps us focused on building business value in our code for our customers • i.e. customer requirements
  • 153. Resources • BDD • http://behaviour-driven.org/ • Cucumber • http://cukes.info • http://github.com/aslakhellesoy/cucumber • Rspec Beta Book • http://pragprog.com/titles/achbd/the-rspec- book
  • 154. Resources • My Blog • http://alexjsharp.com • I’ll post these slides there • My github account • http://github.com/ajsharp • Questions? • ajsharp@frothlogic.com