bdd: telling stories through code [for technotts]

145
@TheMattBrunt BEHAVIOUR DRIVEN DEVELOPMENT TELLING STORIES THROUGH CODE

Upload: matt-brunt

Post on 11-Jan-2017

806 views

Category:

Software


1 download

TRANSCRIPT

Page 1: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

BEHAVIOUR DRIVEN DEVELOPMENT

TELLING STORIES THROUGH CODE

Page 2: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

ABOUT THE AUTHOR…

Page 3: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Senior Software Engineer at Viva IT

@TheMattBrunt @PHPem

Page 4: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

THE PROLOGUE

Page 5: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

BEFORE WE TALK ABOUT BDD

Page 6: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

LET’S TALK ABOUT TESTING

Page 7: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

WHO HERE WRITES TESTS?

Page 8: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

AFTER CODE?

Page 9: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

BEFORE CODE?

Page 10: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

BE HONEST...

Page 11: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 12: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 13: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

TERMINOLOGY

Page 14: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

UNIT TESTS

Page 15: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

INTEGRATION TESTS

Page 16: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 17: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

FUNCTIONAL TESTS

Page 18: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 19: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

ACCEPTANCE TESTS

Page 20: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 21: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

REJECTION TESTS

Page 22: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

TESTING PYRAMID

Page 23: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

COMPONENTS IN ISOLATION

COMPONENTS WORKING TOGETHER

END-TO-END TESTS

Page 24: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

UNIT TESTS

INTEGRATION TESTS

UI TESTS

Page 25: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

MORE TERMINOLOGY

Page 26: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

DUMMIES, STUBS, FAKES, MOCKS

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

Page 27: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

CRITERIA, FIXTURES

Page 28: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

EDGE-CASES, END-TO-END

Page 29: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

TESTING IS JARGON-FILLED

Page 30: BDD: Telling stories through code [For TechNotts]

@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 31: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 32: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

WHAT DOES IT ALL MEAN?

Page 33: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

JARGON BLOCKS ENTRY

Page 34: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

IGNORE JARGON

Page 35: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

TEST TO FEEL COMFORTABLE

Page 36: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 37: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

THE ORIGIN STORY

Page 38: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

TDD VS BDD

Page 39: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

BEHAVIOUR DRIVEN DEVELOPMENT

Page 40: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

HOW DO THEY GET ALONG?

Page 41: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

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

Page 42: BDD: Telling stories through code [For TechNotts]

@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 43: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

SECOND-GENERATIONBREAK DOWN

Page 44: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

MULTIPLE-STAKEHOLDERBREAK DOWN

Page 45: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

AGILE METHODOLOGYBREAK DOWN

Page 46: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

MULTIPLE STAKEHOLDERS

Page 47: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

UBIQUITOUS LANGUAGEAN IMPORTANT PART OF BDD IS…

Page 48: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

CONVERSATIONS ARE KEY

Page 49: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

HAVING CONVERSATIONS

CAPTURING CONVERSATIONS> AUTOMATING

CONVERSATIONS>

Page 50: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

HAVE CONVERSATIONS BEFORE YOU START WRITING CODE

Page 51: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

CAPTURE THE CONVERSATIONS SO YOU CAN USE THEM TO DRIVE DEVELOPMENT

Page 52: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

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

LIZ KEOGH

Page 53: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 54: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

CONVERSATIONS ARE KEY

Page 55: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

EXAMPLES ARE ESSENTIAL

Page 56: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

LET’S MEET THE CHARACTERS OF OUR STORY

Page 57: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

JBEHAVEJAVA HAS

Page 58: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

JDAVEJAVA HAS

???J

Page 59: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

SPECFLOW.NET HAS

Page 60: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

NSPEC.NET HAS

Page 61: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

BEHATPHP HAS

???

Page 62: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

PHPSPECPHP HAS

Page 63: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

BEHAVEPYTHON HAS

Page 64: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

LETTUCEPYTHON HAS

Page 65: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

CUCUMBERRUBY HAS

Page 66: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

RSPECRUBY HAS

Page 67: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

TYPES OF BDD

Page 68: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

SPEC BDD

Page 69: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

STORY BDD (SCENARIOS)

Page 70: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

PICK THE RIGHT TOOL FOR THE JOB

Page 71: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

COMPONENTS IN ISOLATION

COMPONENTS WORKING TOGETHER

END-TO-END TESTS

SPEC BDD

Page 72: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

COMPONENTS IN ISOLATION

COMPONENTS WORKING TOGETHER

END-TO-END TESTS

SCENARIO BDD

Page 73: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

WE’LL BE LOOKING AT SCENARIO BDD

Page 74: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

SO, HOW DO WE WORK WITH THIS?

Page 75: BDD: Telling stories through code [For TechNotts]

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

GHERKIN DSL

Page 76: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

HUMAN READABLEGHERKIN IS…

Page 77: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

KEYWORD BASEDGHERKIN IS…

Page 78: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

LINE ORIENTEDGHERKIN IS…

Page 79: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

DOCUMENTATIONGHERKIN IS…

Page 80: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

AUTOMATIONGHERKIN ALLOWS…

Page 81: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

DEVELOPERS LOVE AUTOMATION

Page 82: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

BE DESCRIPTIVE

Page 83: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

WRITING STORIES

Page 84: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

FEATURES ARE STORIES

Page 85: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

SINGLE FEATURE PER FILE

Page 86: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

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

Page 87: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

SCENARIOS

Page 88: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

SCENARIOS ARE EXAMPLES

Page 89: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

EXAMPLES ARE ESSENTIAL

Page 90: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

MULTIPLE SCENARIOSFEATURES CAN HAVE

Page 91: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 92: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

SORRY…

Page 93: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

STEPS

Page 94: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

MULTIPLE STEPSSCENARIOS HAVE…

Page 95: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 96: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

IMPORTANT KEYWORDS

Page 97: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

GIVENPUTS THE SYSTEM IN A KNOWN STATE

Page 98: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

WHENDESCRIBE A KEY ACTION

Page 99: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

THENDESCRIBE AN OBSERVABLE OUTCOME

Page 100: BDD: Telling stories through code [For TechNotts]

@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 101: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

ANDBUT THERE’S ALSO…

Page 102: BDD: Telling stories through code [For TechNotts]

@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 103: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

STORY STRUCTURE: THE MAKEUP OF A FEATURE FILE

Page 104: BDD: Telling stories through code [For TechNotts]

@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 105: BDD: Telling stories through code [For TechNotts]

@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 106: BDD: Telling stories through code [For TechNotts]

@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 107: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

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

Page 108: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

STEP DEFINITIONS

Page 109: BDD: Telling stories through code [For TechNotts]

@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 110: BDD: Telling stories through code [For TechNotts]

@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 111: BDD: Telling stories through code [For TechNotts]

@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 112: BDD: Telling stories through code [For TechNotts]

@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 113: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 114: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

ARGUMENTS

Page 115: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 116: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

THAT’S BETTER

Page 117: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

TAGS

Page 118: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

SUITES & PROFILES

Page 119: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

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

SUITES ALLOW YOU TO…

Page 120: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

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

FOR EXAMPLE:

Page 121: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

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

FOR EXAMPLE:

Page 122: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

YOU CAN USE THE SAME FEATURE FILE TO TEST DIFFERENT IMPLEMENTATIONS

WITH SUITES AND TAGS…

Page 123: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

YOU CAN CHANGE IMPLEMENTATION WITHOUT CHANGING YOUR DOCUMENTED BUSINESS RULES

WITH SUITES AND TAGS…

Page 124: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

THIS IS WHERE THE POWER LIES

FOR ME…

Page 125: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 126: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

IMPLEMENTATION CHANGES MORE FREQUENTLY THAN BUSINESS RULES

Page 127: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

WRITING A GOOD STORY

Page 128: BDD: Telling stories through code [For TechNotts]

@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

Page 129: BDD: Telling stories through code [For TechNotts]

@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

Page 130: BDD: Telling stories through code [For TechNotts]

@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 131: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

DON’T WRITE IMPLEMENTATION IN FEATURES

Page 132: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

THE CODA

Page 133: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 134: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

STEP ARGUMENT TRANSFORMATIONS

Page 135: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

RETURN US AN OBJECT

LOOK FOR THIS

Page 136: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

Page 137: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

HOOKS

Page 138: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

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

HOOKS

Page 139: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

IN SUMMARY

Page 140: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

CONVERSATIONS.

CONVERSATIONS.

CONVERSATIONS.

CONVERSATIONS.

CONVERSATIONS.

Page 141: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

BEGINNING: HAVE A CONVERSATION, CAPTURE THAT CONVERSATION

MIDDLE: AUTOMATE AND IMPLEMENT THAT CONVERSATION

END: HAPPY STAKEHOLDERS AND WELL BUILT SOFTWARE

Page 142: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

STORIES TOLD BY REAL WORLD EXAMPLES.

USER STORIES AS REQUIREMENTS.

INVOLVE MULTIPLE STAKEHOLDERS.

WRITE FEATURES BEFORE CODE.

WRITE FEATURES WITHOUT IMPLEMENTATION.

Page 143: BDD: Telling stories through code [For TechNotts]

@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 144: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

@TheMattBrunt @PHPem [email protected]

Page 145: BDD: Telling stories through code [For TechNotts]

@TheMattBrunt

THANKS FOR LISTENING