Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A short introduction to BDD

A short introduction to BDD

Jakub Zalas

August 06, 2014
Tweet

More Decks by Jakub Zalas

Other Decks in Programming

Transcript

  1. A short introduction to BDD
    (BDD from the eyes of a test-first maniac)
    by Jakub Zalas
    Polish Developers Meetup
    in London

    View Slide

  2. @jakzal
    @jakub_zalas
    @SensioLabsUK
    £

    View Slide

  3. Act 1: Going inside out
    or how it all started

    View Slide

  4. Test Driven Development

    View Slide

  5. Test Driven Development
    Introducing BDD, Dan North
    http://dannorth.net/introducing-bdd/

    View Slide

  6. Test Driven Development
    Behaviour
    Introducing BDD, Dan North
    http://dannorth.net/introducing-bdd/

    View Slide

  7. public class DeliveryRepositoryTest extends TestCase {
    public void testFindDelivery() {
    // ...
    }
    public void testFindDelivery2() {
    // ...
    }
    }

    View Slide

  8. public class DeliveryRepositoryTest extends TestCase {
    public void testFindsDeliveryByTrackingCode() {
    // ...
    }
    public void testFailsForInvalidTrackingCode() {
    // ...
    }
    }
    DeliveryRepository
    •  finds delivery by tracking code
    •  fails for invalidtracking code

    View Slide

  9. public class DeliveryControllerTest extends WebTestCase {
    public void testItShowsDeliveryDetailsForAValidTrackingCode() {
    // ...
    }
    public void testItDoesNotShowADeliveryForExpiredTrackingCode() {
    // ...
    }
    public void testItDoesNotShowADeliveryDeliveredMoreThanAMonthAgo() {
    // ...
    }
    }
    DeliveryController
    •  it shows delivery details for a valid tracking code
    •  it does not show a delivery for expired tracking code
    •  it does not show a delivery delivered more than a month ago

    View Slide

  10. Act 2: Improving communication
    or how I thought I got it right

    View Slide

  11. Customers should be able to
    sign in!
    Avatars generated on http://www.customsouthparks.com/

    View Slide

  12. 1. Open a browser
    2. Put the site URL in the browser and press enter
    3. Give username
    4. Give password
    5. Press submit button
    6. Check if I gained access to the secured area

    View Slide

  13. package poldev.controller;
    public class AuthController
    {
    public void signIn()
    {
    // ...
    }
    }

    View Slide

  14. Signing in

    View Slide

  15. As a Customer
    I want to sign in
    In order to be signed in

    View Slide

  16. As a Customer
    I want to sign in
    In order to be signed in track my deliveries

    View Slide

  17. As an Customer Owner
    I want to sign in
    In order to be signed in track my deliveries

    View Slide

  18. As an Customer Owner
    I want to sign in Customers to sign in
    In order to be signed in track my their deliveries

    View Slide

  19. When an anonymous user goes to the deliveries
    page
    Then he should see the signin form
    And he shouldn't see any delivery details

    View Slide

  20. When a Customer goes to the deliveries page
    And gives his login details
    Then he should see a list of his deliveries

    View Slide

  21. Feature: Tracking deliveries
    As a Customer
    I need to see a status of my delivery
    So I could know when it's going to be delivered

    View Slide

  22. Feature: Tracking deliveries
    As a Customer
    I need to see a status of my delivery
    So I could know when it's going to be delivered

    View Slide

  23. Feature: Tracking deliveries
    As a Customer
    I need to see a status of my delivery
    So I could know when it's going to be delivered
    Scenario: Clicking a tracking URL
    Scenario: Clicking a tracking URL month after delivery

    View Slide

  24. Feature: Tracking deliveries
    As a Customer
    I need to see a status of my delivery
    So I could know when it's going to be delivered
    Scenario: Clicking a tracking URL
    Given I am waiting for a delivery
    And I received a confirmation message
    When I click the tracking URL from the message
    Then I should see a status of my delivery
    Scenario: Clicking a tracking URL month after delivery
    Given I my package was delivered a month ago
    And I kept the confirmation message
    When I click the tracking URL from the message
    Then I should be informed the tracking URL has expired

    View Slide

  25. Feature: Tracking deliveries
    As a Customer
    I need to see a status of my delivery
    So I could know when it's going to be delivered
    Scenario: Clicking a tracking URL
    Given I am waiting for a delivery
    And I received a confirmation message
    When I click the tracking URL from the message
    Then I should see a status of my delivery
    Scenario: Clicking a tracking URL month after delivery
    Given I my package was delivered a month ago
    And I kept the confirmation message
    When I click the tracking URL from the message
    Then I should be informed the tracking URL has expired

    View Slide

  26. Failing
    step
    Failing
    test
    Code
    Refactor
    Passing
    step
    External quality
    Internal quality

    View Slide

  27. Act 3: Going outside in
    or focusing on a goal

    View Slide

  28. "I need Customers to sign into the
    site to track their delivery."
    Mr Client

    View Slide

  29. As a Customer
    I need to sign into the site
    So I could track my delivery

    View Slide

  30. As a Customer
    I need to see my deliveries
    So I could know when it's going to
    be delivered

    View Slide

  31. WHAT'S
    THE GOAL?

    View Slide

  32. THE CLIENT
    CAME WITH A
    SOLUTION

    View Slide

  33. "I need users to sign into the site to track their
    delivery."
    "Why?"
    "So they could see where's their package."
    "Why?"
    "What do you mean? They need to track their
    deliveries."
    "Yes, but why?"

    View Slide

  34. "Well, our mission is to offer the most
    customer friendly courier services. We want to
    increase the number of satisfied customers."
    "Aha!"
    "So they wouldn't get impatient and file
    complaints when the delivery is delayed."
    "Why?"
    "So they could know when is it going to be
    delivered."
    "Why?"

    View Slide

  35. < 5% of
    customers
    filing
    complaints
    Customers
    Support
    Notifications
    Contact the Customer
    if delivery is delayed
    Add expected delivery
    time to the
    confirmation message
    SMS notifications
    Add a tracking URL to
    the confirmation
    message
    E-mail notifications
    List of deliveries after
    signing in
    Prevent
    complaints
    Check delivery
    status
    Why? Who? How? What?

    View Slide

  36. MAKE
    IMPACTS
    NOT
    SOFTWARE
    Gojko Adžić
    impactmapping.org

    View Slide

  37. Thank you!

    View Slide

  38. Credits
    •  https://www.flickr.com/photos/hinkelstone/5166544084
    •  http://www.customsouthparks.com/
    •  http://impactmapping.org
    •  http://dannorth.net/introducing-bdd/

    View Slide