bdd - telling stories through code for phpem

Post on 15-Apr-2017

194 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

@TheMattBrunt

BEHAVIOUR DRIVEN DEVELOPMENT

TELLING STORIES THROUGH CODE

@TheMattBrunt

ABOUT THE AUTHOR…

@TheMattBrunt

Senior Software Engineer at Viva IT

@TheMattBrunt @PHPem

@TheMattBrunt

BEFORE WE TALK ABOUT BDD

@TheMattBrunt

LET’S TALK ABOUT TESTING

@TheMattBrunt

WHO HERE WRITES TESTS?

@TheMattBrunt

AFTER CODE?

@TheMattBrunt

BEFORE CODE?

@TheMattBrunt

BE HONEST...

@TheMattBrunt

@TheMattBrunt

@TheMattBrunt

TERMINOLOGY

@TheMattBrunt

UNIT TESTS

@TheMattBrunt

INTEGRATION TESTS

@TheMattBrunt

@TheMattBrunt

FUNCTIONAL TESTS

@TheMattBrunt

@TheMattBrunt

ACCEPTANCE TESTS

@TheMattBrunt

@TheMattBrunt

REJECTION TESTS

@TheMattBrunt

TESTING PYRAMID

@TheMattBrunt

COMPONENTS IN ISOLATION

COMPONENTS WORKING TOGETHER

END-TO-END TESTS

@TheMattBrunt

UNIT TESTS

INTEGRATION TESTS

UI TESTS

@TheMattBrunt

MORE TERMINOLOGY

@TheMattBrunt

DUMMIES, STUBS, FAKES, MOCKS

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

@TheMattBrunt

CRITERIA, FIXTURES

@TheMattBrunt

EDGE-CASES, END-TO-END

@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

@TheMattBrunt

@TheMattBrunt

WHAT DOES IT ALL MEAN?

@TheMattBrunt

IGNORE JARGON

@TheMattBrunt

TEST TO FEEL COMFORTABLE

@TheMattBrunt

@TheMattBrunt

TDD VS BDD

@TheMattBrunt

BEHAVIOUR DRIVEN DEVELOPMENT

@TheMattBrunt

HOW DO THEY GET ALONG?

@TheMattBrunt

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

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

@TheMattBrunt

SECOND-GENERATIONBREAK DOWN

@TheMattBrunt

MULTIPLE-STAKEHOLDERBREAK DOWN

@TheMattBrunt

AGILE METHODOLOGYBREAK DOWN

@TheMattBrunt

MULTIPLE STAKEHOLDERS

@TheMattBrunt

UBIQUITOUS LANGUAGEAN IMPORTANT PART OF BDD IS…

@TheMattBrunt

CONVERSATIONS ARE KEY

@TheMattBrunt

HAVING CONVERSATIONS

CAPTURING CONVERSATIONS> AUTOMATING

CONVERSATIONS>

@TheMattBrunt

HAVE CONVERSATIONS BEFORE YOU START WRITING CODE

@TheMattBrunt

CAPTURE THE CONVERSATIONS SO YOU CAN USE THEM TO DRIVE DEVELOPMENT

@TheMattBrunt

@TheMattBrunt

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

LIZ KEOGH

@TheMattBrunt

EXAMPLES ARE ESSENTIAL

@TheMattBrunt

TYPES OF BDD

@TheMattBrunt

SPEC BDD

@TheMattBrunt

STORY BDD (SCENARIOS)

@TheMattBrunt

PICK THE RIGHT TOOL FOR THE JOB

@TheMattBrunt

COMPONENTS IN ISOLATION

COMPONENTS WORKING TOGETHER

END-TO-END TESTS

SPEC BDD

@TheMattBrunt

COMPONENTS IN ISOLATION

COMPONENTS WORKING TOGETHER

END-TO-END TESTS

SCENARIO BDD

@TheMattBrunt

WE’LL BE LOOKING AT SCENARIO BDD

@TheMattBrunt

SO, HOW DO WE WORK WITH THIS?

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

GHERKIN DSL

@TheMattBrunt

HUMAN READABLEGHERKIN IS…

@TheMattBrunt

KEYWORD BASEDGHERKIN IS…

@TheMattBrunt

LINE ORIENTEDGHERKIN IS…

@TheMattBrunt

DOCUMENTATIONGHERKIN IS…

@TheMattBrunt

AUTOMATIONGHERKIN ALLOWS…

@TheMattBrunt

DEVELOPERS LOVE AUTOMATION

@TheMattBrunt

WRITING STORIES

@TheMattBrunt

BE DESCRIPTIVE

@TheMattBrunt

FEATURES ARE STORIES

@TheMattBrunt

SINGLE FEATURE PER FILE

@TheMattBrunt

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

@TheMattBrunt

SCENARIOS

@TheMattBrunt

SCENARIOS ARE EXAMPLES

@TheMattBrunt

EXAMPLES ARE ESSENTIAL

@TheMattBrunt

MULTIPLE SCENARIOSFEATURES CAN HAVE

@TheMattBrunt

@TheMattBrunt

SORRY…

@TheMattBrunt

STEPS

@TheMattBrunt

MULTIPLE STEPSSCENARIOS HAVE…

@TheMattBrunt

@TheMattBrunt

IMPORTANT KEYWORDS

@TheMattBrunt

GIVENPUTS THE SYSTEM IN A KNOWN STATE

@TheMattBrunt

WHENDESCRIBE A KEY ACTION

@TheMattBrunt

THENDESCRIBE AN OBSERVABLE OUTCOME

@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

@TheMattBrunt

ANDBUT THERE’S ALSO…

@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

@TheMattBrunt

STORY STRUCTURE: THE MAKEUP OF A FEATURE FILE

@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

@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

@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

@TheMattBrunt

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

@TheMattBrunt

STEP DEFINITIONS

@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

@TheMattBrunt

@TheMattBrunt

ARGUMENTS

@TheMattBrunt

@TheMattBrunt

THAT’S BETTER

@TheMattBrunt

TAGS

@TheMattBrunt

SUITES & PROFILES

@TheMattBrunt

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

SUITES ALLOW YOU TO…

@TheMattBrunt

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

FOR EXAMPLE:

@TheMattBrunt

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

FOR EXAMPLE:

@TheMattBrunt

YOU CAN USE THE SAME FEATURE FILE TO TEST DIFFERENT IMPLEMENTATIONS

WITH SUITES AND TAGS…

@TheMattBrunt

YOU CAN CHANGE IMPLEMENTATION WITHOUT CHANGING YOUR DOCUMENTED BUSINESS RULES

WITH SUITES AND TAGS…

@TheMattBrunt

THIS IS WHERE THE POWER LIES

FOR ME…

@TheMattBrunt

IMPLEMENTATION CHANGES MORE FREQUENTLY THAN BUSINESS RULES

@TheMattBrunt

WRITING A GOOD STORY

@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

@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

@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”?

@TheMattBrunt

DON’T WRITE IMPLEMENTATION IN FEATURES

@TheMattBrunt

THE CODA

@TheMattBrunt

@TheMattBrunt

STEP ARGUMENT TRANSFORMATIONS

@TheMattBrunt

RETURN US AN OBJECT

LOOK FOR THIS

@TheMattBrunt

@TheMattBrunt

HOOKS

@TheMattBrunt

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

HOOKS

@TheMattBrunt

IN SUMMARY

@TheMattBrunt

CONVERSATIONS.

CONVERSATIONS.

CONVERSATIONS.

CONVERSATIONS.

CONVERSATIONS.

@TheMattBrunt

BEGINNING: HAVE A CONVERSATION, CAPTURE THAT CONVERSATION

MIDDLE: AUTOMATE AND IMPLEMENT THAT CONVERSATION

END: HAPPY STAKEHOLDERS AND WELL BUILT SOFTWARE

@TheMattBrunt

STORIES TOLD BY REAL WORLD EXAMPLES.

USER STORIES AS REQUIREMENTS.

INVOLVE MULTIPLE STAKEHOLDERS.

WRITE FEATURES BEFORE CODE.

WRITE FEATURES WITHOUT IMPLEMENTATION.

@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

@TheMattBrunt

@TheMattBrunt @PHPem matt@mfyu.co.uk

@TheMattBrunt

THANKS FOR LISTENING

top related