$30 off During Our Annual Pro Sale. View Details »

Behavior Driven Development

Behavior Driven Development

🇫🇷
Le métier et la qualité en première ligne grâce au Behavior Driven Development

Cette question vous parle ? Alors peut-être que le Behavior Driven Development va vous intéresser. Cette méthode, souvent utilisée dans un contexte Agile et digne héritière de la mouvance TDD, aide les équipes (Three Amigos) à focaliser leur attention sur le besoin des utilisateurs et la mise en oeuvre des comportements associés au sein d'un produit.

Dans cette session nous vous proposons de revenir sur l'émergence du BDD, de voir comment le mettre en place efficacement au sein d’une équipe produit et d’explorer ses liens avec les autres composantes du Craftsmanship comme le TDD, le DDD ou l’Event Storming.

🇬🇧
Business and quality first, thanks to Behavior Driven Development

TODO: translate abstract

[email protected]

December 16, 2021
Tweet

Other Decks in Programming

Transcript

  1. Business and quality first
    Thanks to
    Behavior Driven Development
    󰞲
    󰥤 󰠁
    Sylvain PONTOREAU
    Julien PAVON

    View Slide

  2. A little bit of history

    View Slide

  3. Work
    together
    Respect
    Introduced by Kent Beck in 1999!
    eXtreme Programming
    Communication
    Simplicity Quality Feedback

    View Slide

  4. Informative
    workspace
    Energized work
    Some practices
    eXtreme Programming
    Whole team
    Stories Pair Test first

    View Slide

  5. Test Driven Development
    RED GREEN
    REFACTOR
    Write a failing
    automated test
    Change the
    implementation to
    make the test pass
    ● Remove duplication
    ● keep things clear and simple
    ● code optimization
    ● ...

    View Slide

  6. As a customer
    I want to list all the toys
    So I can buy a gift for my
    children
    Product Owner
    Communication
    const filter = getQueryParams();
    const catalog = new Catalog();
    return catalog.getItems(filter);
    Developer
    “Some articles are missing
    when a user search for
    games on the online store”
    QA
    󰞲
    󰥤 󰠁

    View Slide

  7. Small presentation of who we are…
    Sylvain PONTOREAU
    @spontoreau
    Julien PAVON
    @JulienPavon

    View Slide

  8. What you will see today
    Implement it
    effectively
    Gherkin syntax
    overview
    What is BDD
    Business
    Documentation
    Feedback from
    experiences

    View Slide

  9. BDD in a nutshell

    View Slide

  10. Test Driven Development
    Behavior
    TDD done well!
    Introduced by Dan North in 2003!
    What is Behavior Driven Development?
    Better
    communication
    Test

    View Slide

  11. Acceptance testing != (Unit | UI) tests
    (TDD | BDD) ➡ testing methodologies
    TDD != Unit testing
    Acceptance testing
    BDD != UI testing
    TDD/ATDD
    BDD
    ● 👉 (TDD | BDD) == acceptance testing
    ● 👉 BDD == driving development by focusing on software behaviors

    View Slide

  12. Acceptance testing
    BDD (Gherkin)
    There is a context
    Let’s do something
    Some expectations should happened
    Arrange
    Act
    Assert
    TDD (AAA)
    Given
    When
    Then
    Means

    View Slide

  13. Getting started with an example
    User story: I can change the price of a toy
    As a toy store manager
    I want to change the price of a toy
    So that I can correct a pricing error

    View Slide

  14. A scenario describing the UI
    Given I go on the back office
    And I open a toy page
    When I type a price in the price input
    And I click on the save button
    Then I should see a toaster saying that the toy has been updated
    And I should see the new price on the toy page
    Often the first example you see on internet … 🤔
    What I need to change
    the price
    How you change the
    price
    Has the price been
    changed?

    View Slide

  15. Why this is not the best option?
    It describes:
    "How to update a toy price with the back office application"
    ⚠ Problems:
    ● What happens if you change the UI?
    ✋ But the behavior is “exactly” the same!
    ● What about doing the same with an API?
    ○ ➡ You have to write another scenario … 😞

    View Slide

  16. A scenario describing the API
    Given I created an HttpClient
    And I configure it with the backend URI
    When I prepare the payload with the new price
    And I call the URL “item/:id/price” with the payload
    Then I should get a 200 status code response
    And I should get the item with new price at the URL “item/:id”
    It can really be worse … 😅
    What I need to change
    the price
    How you change the
    price
    Has the price been
    changed?

    View Slide

  17. Focus on the behavior
    Given a toy store manager
    And a toy
    When updating the toy’s price
    Then the price of the toy should be updated
    It’s simple as that 😉
    What I need to change
    the price
    How you change the
    price
    Has the price been
    changed?

    View Slide

  18. Focus on the behavior
    We can be even more concise 🤯
    ● Expressiveness and storytelling are much clearer (and better that reusable steps)
    Toy
    Up a
    p i
    Sto
    ma r
    Toy’s p i
    up d
    ● We are also focus on ubiquitous language:
    When a store manager updates the price of a toy
    Then the price of the toy should be updated

    View Slide

  19. Last words on our scenario
    Now it describes:
    "How to update a toy’s price and that’s all"
    Key points:
    ● 👍 It can be used to execute tests everywhere:
    ○ Website
    ○ Mobile
    ○ Api
    ○ …
    ● 😍 We have only one scenario to maintain

    View Slide

  20. Gherkin syntax

    View Slide

  21. Start by giving your scenario a name:
    The basics
    Scenario: Add a new toy in the store
    For your first scenario, keep it simple using only the basics keywords:
    GIVEN WHEN THEN
    Given the toy’s store is empty
    When a store manager adds a new toy in the store
    Then the toy’s store should not be empty

    View Slide

  22. More details thanks to …
    Scenario: Add a new toy in the store
    Given the toy’s store is empty
    When a store manager adds this toy in the store:
    | Name | Cubetto |
    | Price | 199.99 $ |
    | Brand | Primo Toys |
    Then the toy named "Cubetto" should be added in the store
    💡 To keep your scenarios simple to read and maintain, use tables with small pieces of data
    TABLES

    View Slide

  23. One scenario with many examples
    Scenario Outline: Add a new toy in the store
    Given the toy’s store is empty
    When a store manager adds this toy in the store:
    | Name | |
    | Price | |
    | Brand | |
    Then the toy named "" should be added in the store
    Examples:
    | Name | Price | Brand |
    | Cubetto | 199.99 $ | Primo Toys |
    | Gravity Maze | 29.99 $ | ThinkFun |
    💡 Again! Keep your scenarios simple to read and use tables with small pieces of data
    Transform your scenario a little bit
    SCENARIO
    SCENARIO
    OUTLINE
    EXAMPLES
    ➡ ➕

    View Slide

  24. More keywords
    Scenario: Do not notify when restock a toy
    Given a toy out of stock
    And a customer has not activated notifications for the toy
    When a toy is restock in the store
    Then the toy can be purchased again
    But the customer is not notified that the toy is available
    AND BUT
    💡 Do not add too much steps and if necessary split your scenarios into smaller ones
    You can chain your steps with more keywords:

    View Slide

  25. Another one
    Feature: Restock a toy
    Background:
    Given a toy out of stock
    Scenario: Restock a toy
    When a toy is restock in the store
    Then the toy can be purchased again
    Scenario: Do not notify customer with notifications disabled
    Given a customer with notifications disabled
    When a toy is restock in the store
    Then the customer is not notified that the toy is available
    BACKGROUND

    ● Be careful of the readability of your scenarios
    here
    You can share some steps between all the scenarios with…
    ● Sometimes duplication is not a bad thing
    ● Scrolling up every time to understand a scenario
    can be very uncomfortable

    View Slide

  26. @TAG
    EXAMPLE
    Scenario organization keywords:
    How to improve the structure
    RULE
    Introduced in the v6 ➡ describe a business rule to implement as part of a
    feature
    Alias for Scenario
    Add tags on features, scenarios, examples, rules (helpful for filtering/searching)

    View Slide

  27. From the trench

    View Slide

  28. ● 👉 Convincing in a relevant way
    ● 🔎 Now let’s share two cases we had
    It is not necessarily simple for our stakeholders…
    How to start?
    🤔 😩
    Benefits are not
    always clear
    Often misunderstood

    View Slide

  29. From the trench…
    …agility embraced

    View Slide

  30. A good case to start with
    No fear of change
    Pluridisciplinary
    teams
    Teams already
    wrote scenarios
    󰥤
    Product owner
    󰞲
    QA
    󰠁
    Developers
    📱
    Mockups based
    A company where agility is embraced 👍

    View Slide

  31. But something was not working
    Writing scenarios
    Communication
    Who is responsible for
    that?
    UI scenarios, what
    about backend tests?
    Misunderstanding
    =
    Waste of time
    Same thing but
    different words

    View Slide

  32. So we tried that
    Recurrent
    grooming sessions
    📅 󰥤󰠁󰞲 🚫
    ● First session ➡ Existing UI scenario + replace things like “click on”
    15 minutes everyday Three amigos No mockups
    ● Ask PO to try rewriting an another existing in this way for the next session
    ● Finally those sessions become rituals
    ● Discuss and refine together
    ● … and PO takes the lead

    View Slide

  33. And some months later!
    Writing scenarios No more “click on” in
    scenarios
    Each team member
    participate
    Share the same
    language
    Communication Glossary for the
    ubiquitous language
    Living doc deployed
    automatically
    Test practices Execution on several
    layers

    View Slide

  34. From the trench…
    …the worst case

    View Slide

  35. A little bit of context:
    ● No PO or PM
    ● 0 specs (or at least few old fashioned docs)
    ● No maturity on testing methodologies
    ● No QA in the team
    ● Questionable software quality standards
    ● Not really Agile
    The worst case
    Maybe a bad start, but:
    ● 👍 Want to increase the quality
    ● 👍 Open to change practices
    ● 👍 Identified business expert

    View Slide

  36. Be a coach and plan a soft transition
    Change can be scary
    How we can start?
    What about talking and
    taking notes?
    󰞴
    Coach (you)
    Business expert
    󰠅
    You want to do your thing
    there, the scenarios…
    Business knowledge is
    more important
    Ok got it!
    Do you have a simple
    case to start with?

    View Slide

  37. 😅
    The first result I had…
    But no shame, there is plenty to work with!

    View Slide

  38. Getting out of the comfort zone is not that easy
    Give honest feedbacks
    Do you understand the goal?
    Yeah, but to be honest it
    was too technical…
    󰞴
    Coach (you)
    Business expert
    󰠅
    Can you write some of your
    scenario things with that?
    Our session didn’t really
    help me to understand the
    business…
    I don’t know how to do it then

    Don’t worry!
    I have questions regarding
    changing the period.

    View Slide

  39. Asking for details about the business out everything
    Lead the interview
    Who is changing the period?
    An agent.
    󰠅
    Business expert
    Coach (you)
    󰞴
    A customer call the agency to
    ask for a period change.
    Sound great, what is
    expected at the end?
    Customer receives a
    confirmation.
    Cool, how he does it?
    Anything else?
    Yeah of course. So it seems
    we have a case for a story!
    Yes, the invoice must be
    up to date … obviously.

    View Slide

  40. Not that bad!
    The second result…
    👍 It’s enough for to writing a scenario

    View Slide

  41. Ubiquitous and domain elements
    And you have more
    Ac o ?
    Com
    d?
    Ag eg ?
    Eve
    s?
    Aka a business user
    Aka
    a
    unit to
    execute
    the
    behavior
    Aka a business object uses
    by the behavior
    Aka something that happen
    in the domain

    View Slide

  42. So my customer is almost ready for Event Storming and DDD 😁
    When
    And from a domain perspective
    Domain
    elements
    BDD
    scenario
    An order
    Aggregate
    📃
    Then
    An agent
    Actor
    😀
    Extends
    rental period
    Command
    🗓
    Rental period
    extended
    Event

    Given

    View Slide

  43. Our first scenario together
    Probably a first victory🎉
    Given a customer’s order
    When an agent extends the rental period of the order
    Then the number of rental days in the order has been changed
    And the price of the invoice is updated
    And the customer is notified
    Or e
    Ex e d
    re l i d
    Age
    Ren d
    c a g
    In o is
    up d
    Cus r i
    no fi

    View Slide

  44. Living documentation

    View Slide

  45. Living documentation
    List of all
    behaviors
    Tests reports
    One doc for each
    release
    Onboarding Support resource
    Share with your
    stakeholders
    Few steps to achieve that
    Some goals

    View Slide

  46. Online solutions
    Cucumber Studio Cucumber Reports

    View Slide

  47. Or a poor old script… 😁
    Other tools
    Pickles Cukedoctor

    View Slide

  48. Go further

    View Slide

  49. Books

    View Slide

  50. Slides
    https://speakerdeck.com/spontoreau/behavior-driven-development

    View Slide

  51. Questions?

    View Slide

  52. Thanks!

    View Slide