bdd - telling stories through code for phpem

125
@TheMattBrunt BEHAVIOUR DRIVEN DEVELOPMENT TELLING STORIES THROUGH CODE

Upload: matt-brunt

Post on 15-Apr-2017

189 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: BDD - telling stories through code for PHPem

@TheMattBrunt

BEHAVIOUR DRIVEN DEVELOPMENT

TELLING STORIES THROUGH CODE

Page 2: BDD - telling stories through code for PHPem

@TheMattBrunt

ABOUT THE AUTHOR…

Page 3: BDD - telling stories through code for PHPem

@TheMattBrunt

Senior Software Engineer at Viva IT

@TheMattBrunt @PHPem

Page 4: BDD - telling stories through code for PHPem

@TheMattBrunt

BEFORE WE TALK ABOUT BDD

Page 5: BDD - telling stories through code for PHPem

@TheMattBrunt

LET’S TALK ABOUT TESTING

Page 6: BDD - telling stories through code for PHPem

@TheMattBrunt

WHO HERE WRITES TESTS?

Page 7: BDD - telling stories through code for PHPem

@TheMattBrunt

AFTER CODE?

Page 8: BDD - telling stories through code for PHPem

@TheMattBrunt

BEFORE CODE?

Page 9: BDD - telling stories through code for PHPem

@TheMattBrunt

BE HONEST...

Page 10: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 11: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 12: BDD - telling stories through code for PHPem

@TheMattBrunt

TERMINOLOGY

Page 13: BDD - telling stories through code for PHPem

@TheMattBrunt

UNIT TESTS

Page 14: BDD - telling stories through code for PHPem

@TheMattBrunt

INTEGRATION TESTS

Page 15: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 16: BDD - telling stories through code for PHPem

@TheMattBrunt

FUNCTIONAL TESTS

Page 17: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 18: BDD - telling stories through code for PHPem

@TheMattBrunt

ACCEPTANCE TESTS

Page 19: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 20: BDD - telling stories through code for PHPem

@TheMattBrunt

REJECTION TESTS

Page 21: BDD - telling stories through code for PHPem

@TheMattBrunt

TESTING PYRAMID

Page 22: BDD - telling stories through code for PHPem

@TheMattBrunt

COMPONENTS IN ISOLATION

COMPONENTS WORKING TOGETHER

END-TO-END TESTS

Page 23: BDD - telling stories through code for PHPem

@TheMattBrunt

UNIT TESTS

INTEGRATION TESTS

UI TESTS

Page 24: BDD - telling stories through code for PHPem

@TheMattBrunt

MORE TERMINOLOGY

Page 25: BDD - telling stories through code for PHPem

@TheMattBrunt

DUMMIES, STUBS, FAKES, MOCKS

https://adamcod.es/2014/05/15/test-doubles-mock-vs-stub.html

Page 26: BDD - telling stories through code for PHPem

@TheMattBrunt

CRITERIA, FIXTURES

Page 27: BDD - telling stories through code for PHPem

@TheMattBrunt

EDGE-CASES, END-TO-END

Page 28: BDD - telling stories through code for PHPem

@TheMattBrunt

ACCEPTANCE AGILE AUTOMATION BDD BEHAVIOUR BLACK-BOX BOUNDARIES CONTEXTS CRITERIA DDD DOUBLES DUMMIES EDGE-CASES END-TO-END FACTORIES FAKES FEATURES FIXTURES FUNCTIONAL INTEGRATION MOCKS OUTSIDE-IN SCENARIOS SPECS SPIES STUBS TDD UNITS

Page 29: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 30: BDD - telling stories through code for PHPem

@TheMattBrunt

WHAT DOES IT ALL MEAN?

Page 31: BDD - telling stories through code for PHPem

@TheMattBrunt

IGNORE JARGON

Page 32: BDD - telling stories through code for PHPem

@TheMattBrunt

TEST TO FEEL COMFORTABLE

Page 33: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 34: BDD - telling stories through code for PHPem

@TheMattBrunt

TDD VS BDD

Page 35: BDD - telling stories through code for PHPem

@TheMattBrunt

BEHAVIOUR DRIVEN DEVELOPMENT

Page 36: BDD - telling stories through code for PHPem

@TheMattBrunt

HOW DO THEY GET ALONG?

Page 37: BDD - telling stories through code for PHPem

@TheMattBrunt

BDD IS TDD ‘DONE RIGHT’IT’S OFTEN SAID THAT…

Page 38: BDD - telling stories through code for PHPem

@TheMattBrunt

BDD IS A SECOND-GENERATION, OUTSIDE-IN, PULL-BASED, MULTIPLE-STAKEHOLDER, MULTIPLE-SCALE, HIGH-AUTOMATION, AGILE METHODOLOGY.

DAN NORTH

http://dannorth.net/whats-in-a-story/

Page 39: BDD - telling stories through code for PHPem

@TheMattBrunt

SECOND-GENERATIONBREAK DOWN

Page 40: BDD - telling stories through code for PHPem

@TheMattBrunt

MULTIPLE-STAKEHOLDERBREAK DOWN

Page 41: BDD - telling stories through code for PHPem

@TheMattBrunt

AGILE METHODOLOGYBREAK DOWN

Page 42: BDD - telling stories through code for PHPem

@TheMattBrunt

MULTIPLE STAKEHOLDERS

Page 43: BDD - telling stories through code for PHPem

@TheMattBrunt

UBIQUITOUS LANGUAGEAN IMPORTANT PART OF BDD IS…

Page 44: BDD - telling stories through code for PHPem

@TheMattBrunt

CONVERSATIONS ARE KEY

Page 45: BDD - telling stories through code for PHPem

@TheMattBrunt

HAVING CONVERSATIONS

CAPTURING CONVERSATIONS> AUTOMATING

CONVERSATIONS>

Page 46: BDD - telling stories through code for PHPem

@TheMattBrunt

HAVE CONVERSATIONS BEFORE YOU START WRITING CODE

Page 47: BDD - telling stories through code for PHPem

@TheMattBrunt

CAPTURE THE CONVERSATIONS SO YOU CAN USE THEM TO DRIVE DEVELOPMENT

Page 48: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 49: BDD - telling stories through code for PHPem

@TheMattBrunt

BDD IS THE ART OF USING EXAMPLES IN CONVERSATIONS TO ILLUSTRATE BEHAVIOUR

LIZ KEOGH

Page 50: BDD - telling stories through code for PHPem

@TheMattBrunt

EXAMPLES ARE ESSENTIAL

Page 51: BDD - telling stories through code for PHPem

@TheMattBrunt

TYPES OF BDD

Page 52: BDD - telling stories through code for PHPem

@TheMattBrunt

SPEC BDD

Page 53: BDD - telling stories through code for PHPem

@TheMattBrunt

STORY BDD (SCENARIOS)

Page 54: BDD - telling stories through code for PHPem

@TheMattBrunt

PICK THE RIGHT TOOL FOR THE JOB

Page 55: BDD - telling stories through code for PHPem

@TheMattBrunt

COMPONENTS IN ISOLATION

COMPONENTS WORKING TOGETHER

END-TO-END TESTS

SPEC BDD

Page 56: BDD - telling stories through code for PHPem

@TheMattBrunt

COMPONENTS IN ISOLATION

COMPONENTS WORKING TOGETHER

END-TO-END TESTS

SCENARIO BDD

Page 57: BDD - telling stories through code for PHPem

@TheMattBrunt

WE’LL BE LOOKING AT SCENARIO BDD

Page 58: BDD - telling stories through code for PHPem

@TheMattBrunt

SO, HOW DO WE WORK WITH THIS?

Page 59: BDD - telling stories through code for PHPem

@TheMattBrunthttps://github.com/cucumber/cucumber/wiki/Gherkin

GHERKIN DSL

Page 60: BDD - telling stories through code for PHPem

@TheMattBrunt

HUMAN READABLEGHERKIN IS…

Page 61: BDD - telling stories through code for PHPem

@TheMattBrunt

KEYWORD BASEDGHERKIN IS…

Page 62: BDD - telling stories through code for PHPem

@TheMattBrunt

LINE ORIENTEDGHERKIN IS…

Page 63: BDD - telling stories through code for PHPem

@TheMattBrunt

DOCUMENTATIONGHERKIN IS…

Page 64: BDD - telling stories through code for PHPem

@TheMattBrunt

AUTOMATIONGHERKIN ALLOWS…

Page 65: BDD - telling stories through code for PHPem

@TheMattBrunt

DEVELOPERS LOVE AUTOMATION

Page 66: BDD - telling stories through code for PHPem

@TheMattBrunt

WRITING STORIES

Page 67: BDD - telling stories through code for PHPem

@TheMattBrunt

BE DESCRIPTIVE

Page 68: BDD - telling stories through code for PHPem

@TheMattBrunt

FEATURES ARE STORIES

Page 69: BDD - telling stories through code for PHPem

@TheMattBrunt

SINGLE FEATURE PER FILE

Page 70: BDD - telling stories through code for PHPem

@TheMattBrunt

Feature: As a [role] I want [feature] So that [benefit]

Page 71: BDD - telling stories through code for PHPem

@TheMattBrunt

SCENARIOS

Page 72: BDD - telling stories through code for PHPem

@TheMattBrunt

SCENARIOS ARE EXAMPLES

Page 73: BDD - telling stories through code for PHPem

@TheMattBrunt

EXAMPLES ARE ESSENTIAL

Page 74: BDD - telling stories through code for PHPem

@TheMattBrunt

MULTIPLE SCENARIOSFEATURES CAN HAVE

Page 75: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 76: BDD - telling stories through code for PHPem

@TheMattBrunt

SORRY…

Page 77: BDD - telling stories through code for PHPem

@TheMattBrunt

STEPS

Page 78: BDD - telling stories through code for PHPem

@TheMattBrunt

MULTIPLE STEPSSCENARIOS HAVE…

Page 79: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 80: BDD - telling stories through code for PHPem

@TheMattBrunt

IMPORTANT KEYWORDS

Page 81: BDD - telling stories through code for PHPem

@TheMattBrunt

GIVENPUTS THE SYSTEM IN A KNOWN STATE

Page 82: BDD - telling stories through code for PHPem

@TheMattBrunt

WHENDESCRIBE A KEY ACTION

Page 83: BDD - telling stories through code for PHPem

@TheMattBrunt

THENDESCRIBE AN OBSERVABLE OUTCOME

Page 84: BDD - telling stories through code for PHPem

@TheMattBrunt

Given I have a “Large T-Shirt” product When I add a “Large T-Shirt” to my basket

Then I should have a “Large T-Shirt” in my basket

Page 85: BDD - telling stories through code for PHPem

@TheMattBrunt

ANDBUT THERE’S ALSO…

Page 86: BDD - telling stories through code for PHPem

@TheMattBrunt

Given I have a “Large T-Shirt” product that costs £9.99

And I have an empty basket

When I add a “Large T-Shirt” to my basket

Then I should have a “Large T-Shirt” in my basket

And the basket total should be £9.99

Page 87: BDD - telling stories through code for PHPem

@TheMattBrunt

STORY STRUCTURE: THE MAKEUP OF A FEATURE FILE

Page 88: BDD - telling stories through code for PHPem

@TheMattBrunt

Feature: As a customer I want to be able to add products to my basket So that I can have a gift for my partner

Scenario: I can add a product to the basket Given I have a "Large T-Shirt" product When I add a “Large T-Shirt” to my basket Then I should have a “Large T-Shirt” in my basket

FEATURE

Page 89: BDD - telling stories through code for PHPem

@TheMattBrunt

SCENARIO

Feature: As a customer I want to be able to add products to my basket So that I can have a gift for my partner

Scenario: I can add a product to the basket Given I have a "Large T-Shirt" product When I add a “Large T-Shirt” to my basket Then I should have a “Large T-Shirt” in my basket

Page 90: BDD - telling stories through code for PHPem

@TheMattBrunt

STEP

Feature: As a customer I want to be able to add products to my basket So that I can have a gift for my partner

Scenario: I can add a product to the basket Given I have a "Large T-Shirt" product When I add a “Large T-Shirt” to my basket Then I should have a “Large T-Shirt” in my basket

Page 91: BDD - telling stories through code for PHPem

@TheMattBrunt

THIS IS GREAT, BUT HOW DOES IT RELATE TO CODE?

Page 92: BDD - telling stories through code for PHPem

@TheMattBrunt

STEP DEFINITIONS

Page 93: BDD - telling stories through code for PHPem

@TheMattBrunt

Given I have a “Large T-Shirt” product When I add that product to my basket Then I should see that product in my basket

Page 94: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 95: BDD - telling stories through code for PHPem

@TheMattBrunt

ARGUMENTS

Page 96: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 97: BDD - telling stories through code for PHPem

@TheMattBrunt

THAT’S BETTER

Page 98: BDD - telling stories through code for PHPem

@TheMattBrunt

TAGS

Page 99: BDD - telling stories through code for PHPem

@TheMattBrunt

SUITES & PROFILES

Page 100: BDD - telling stories through code for PHPem

@TheMattBrunt

TEST DIFFERENT (OR THE SAME) FEATURES WITH DIFFERENT CONFIGURATIONS.

SUITES ALLOW YOU TO…

Page 101: BDD - telling stories through code for PHPem

@TheMattBrunt

YOU CAN HAVE A UI SUITE THAT USES DIFFERENT STEP DEFINITIONS THAN A SERVICE LEVEL SUITE

FOR EXAMPLE:

Page 102: BDD - telling stories through code for PHPem

@TheMattBrunt

THEY COULD ALSO USE DIFFERENT, OR EVEN THE SAME FEATURE FILES

FOR EXAMPLE:

Page 103: BDD - telling stories through code for PHPem

@TheMattBrunt

YOU CAN USE THE SAME FEATURE FILE TO TEST DIFFERENT IMPLEMENTATIONS

WITH SUITES AND TAGS…

Page 104: BDD - telling stories through code for PHPem

@TheMattBrunt

YOU CAN CHANGE IMPLEMENTATION WITHOUT CHANGING YOUR DOCUMENTED BUSINESS RULES

WITH SUITES AND TAGS…

Page 105: BDD - telling stories through code for PHPem

@TheMattBrunt

THIS IS WHERE THE POWER LIES

FOR ME…

Page 106: BDD - telling stories through code for PHPem

@TheMattBrunt

IMPLEMENTATION CHANGES MORE FREQUENTLY THAN BUSINESS RULES

Page 107: BDD - telling stories through code for PHPem

@TheMattBrunt

WRITING A GOOD STORY

Page 108: BDD - telling stories through code for PHPem

@TheMattBrunt

Scenario: I can add a product to my basket

Given I am on the “/product/1” page

When I press “Add to basket”

Then I should see “Playstation 4”

And I should see £250

BAD STORY

Page 109: BDD - telling stories through code for PHPem

@TheMattBrunt

Scenario: I can add a single product to my basket

Given I have a “Playstation 4” that costs £250

When I add the “Playstation 4” to my basket

Then I should have 1 product in my basket

And the basket total should be £250

BETTER STORY

Page 110: BDD - telling stories through code for PHPem

@TheMattBrunt

Scenario: I can add a product to my basket

Given I am on the “/product/1” page

When I press “Add to basket”

Then I should see “Playstation 4”

And I should see £250

WHAT HAPPENS WHEN THE UI CHANGES TO SAY “ADD TO CART”?

Page 111: BDD - telling stories through code for PHPem

@TheMattBrunt

DON’T WRITE IMPLEMENTATION IN FEATURES

Page 112: BDD - telling stories through code for PHPem

@TheMattBrunt

THE CODA

Page 113: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 114: BDD - telling stories through code for PHPem

@TheMattBrunt

STEP ARGUMENT TRANSFORMATIONS

Page 115: BDD - telling stories through code for PHPem

@TheMattBrunt

RETURN US AN OBJECT

LOOK FOR THIS

Page 116: BDD - telling stories through code for PHPem

@TheMattBrunt

Page 117: BDD - telling stories through code for PHPem

@TheMattBrunt

HOOKS

Page 118: BDD - telling stories through code for PHPem

@TheMattBrunt

BEFORE & AFTER THE FOLLOWING: SUITES, FEATURES, SCENARIOS, STEPS

HOOKS

Page 119: BDD - telling stories through code for PHPem

@TheMattBrunt

IN SUMMARY

Page 120: BDD - telling stories through code for PHPem

@TheMattBrunt

CONVERSATIONS.

CONVERSATIONS.

CONVERSATIONS.

CONVERSATIONS.

CONVERSATIONS.

Page 121: BDD - telling stories through code for PHPem

@TheMattBrunt

BEGINNING: HAVE A CONVERSATION, CAPTURE THAT CONVERSATION

MIDDLE: AUTOMATE AND IMPLEMENT THAT CONVERSATION

END: HAPPY STAKEHOLDERS AND WELL BUILT SOFTWARE

Page 122: BDD - telling stories through code for PHPem

@TheMattBrunt

STORIES TOLD BY REAL WORLD EXAMPLES.

USER STORIES AS REQUIREMENTS.

INVOLVE MULTIPLE STAKEHOLDERS.

WRITE FEATURES BEFORE CODE.

WRITE FEATURES WITHOUT IMPLEMENTATION.

Page 123: BDD - telling stories through code for PHPem

@TheMattBrunt

LINKS & READINGhttps://cucumber.io/docs

https://adamcod.es/2014/05/15/test-doubles-mock-vs-stub.html

https://github.com/cucumber/cucumber/wiki/Gherkin

http://dannorth.net/whats-in-a-story/

http://dannorth.net/introducing-bdd/

http://lizkeogh.com/category/bdd/

http://lizkeogh.com/2014/01/22/using-bdd-with-legacy-systems/

http://inviqa.com/insights/bdd-guide

Page 124: BDD - telling stories through code for PHPem

@TheMattBrunt

@TheMattBrunt @PHPem [email protected]

Page 125: BDD - telling stories through code for PHPem

@TheMattBrunt

THANKS FOR LISTENING