Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

A little bit of history

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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 ● ...

Slide 6

Slide 6 text

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 󰞲 󰥤 󰠁

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

BDD in a nutshell

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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?

Slide 15

Slide 15 text

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 … 😞

Slide 16

Slide 16 text

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?

Slide 17

Slide 17 text

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?

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Gherkin syntax

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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 ➡ ➕

Slide 24

Slide 24 text

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:

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

@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)

Slide 27

Slide 27 text

From the trench

Slide 28

Slide 28 text

● 👉 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

Slide 29

Slide 29 text

From the trench… …agility embraced

Slide 30

Slide 30 text

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 👍

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

From the trench… …the worst case

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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?

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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.

Slide 39

Slide 39 text

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.

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

Living documentation

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

Online solutions Cucumber Studio Cucumber Reports

Slide 47

Slide 47 text

Or a poor old script… 😁 Other tools Pickles Cukedoctor

Slide 48

Slide 48 text

Go further

Slide 49

Slide 49 text

Books

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

Questions?

Slide 52

Slide 52 text

Thanks!