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

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

Sylvain PONTOREAU

December 16, 2021
Tweet

More Decks by Sylvain PONTOREAU

Other Decks in Programming

Transcript

  1. Work together Respect Introduced by Kent Beck in 1999! eXtreme

    Programming Communication Simplicity Quality Feedback
  2. 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 • ...
  3. 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 󰞲 󰥤 󰠁
  4. What you will see today Implement it effectively Gherkin syntax

    overview What is BDD Business Documentation Feedback from experiences
  5. Test Driven Development Behavior TDD done well! Introduced by Dan

    North in 2003! What is Behavior Driven Development? Better communication Test
  6. 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
  7. 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
  8. 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
  9. 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?
  10. 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 … 😞
  11. 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?
  12. 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?
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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 | <Name> | | Price | <Price> | | Brand | <Brand> | Then the toy named "<Name>" 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 ➡ ➕
  18. 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:
  19. 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
  20. @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)
  21. • 👉 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
  22. 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 👍
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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?
  28. 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.
  29. 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.
  30. 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
  31. 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
  32. 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
  33. 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