bdd & behat for glasgow php
TRANSCRIPT
@Brunty
BEHAVIOUR DRIVEN DEVELOPMENT & BEHAT
TELLING STORIES THROUGH CODE
@Brunty
Senior Software Engineer Viva IT
@Brunty @PHPem
@Brunty
BEFORE WE TALK ABOUT BDD
@Brunty
TDD VS BDD
@Brunty
BDD IS TDD ‘DONE RIGHT’IT’S OFTEN SAID THAT…
@Brunty
TDD IS BUILDING THE THING RIGHT
@Brunty
BDD IS BUILDING THE RIGHT THING
@Brunty
WE’LL BE LOOKING AT SCENARIO BDD
@Brunty
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/
@Brunty
SECOND-GENERATIONBREAK DOWN
@Brunty
MULTIPLE-STAKEHOLDERBREAK DOWN
@Brunty
AGILE METHODOLOGYBREAK DOWN
@Brunty
MULTIPLE STAKEHOLDERS
@Brunty
CONVERSATIONS ARE KEY
@Brunty
HAVING CONVERSATIONS > CAPTURING
CONVERSATIONSAUTOMATING
CONVERSATIONS>
@Brunty
HAVE CONVERSATIONS BEFORE YOU START WRITING CODE
@Brunty
CAPTURE THE CONVERSATIONS SO YOU CAN USE THEM TO DRIVE DEVELOPMENT
@Brunty
BDD IS THE ART OF USING EXAMPLES IN CONVERSATIONS TO ILLUSTRATE BEHAVIOUR
LIZ KEOGH
@Brunty
EXAMPLES ARE ESSENTIAL
@Bruntyhttps://github.com/cucumber/cucumber/wiki/Gherkin
GHERKIN DSL
@Brunty
HUMAN READABLEGHERKIN IS…
@Brunty
MULTI-LINGUAL SUPPORTTOOLS CAN INCLUDE…
@Brunty
EN-PIRATEINCLUDING
https://github.com/Behat/Gherkin/blob/master/i18n.php#L313
@Brunty
KEYWORD BASEDGHERKIN IS…
@Brunty
LINE ORIENTEDGHERKIN IS…
@Brunty
DOCUMENTATIONGHERKIN IS…
@Brunty
AUTOMATIONGHERKIN ALLOWS…
@Brunty
DEVELOPERS LOVE AUTOMATION
@Brunty
FEATURES ARE STORIES
WHEN WRITING STORIES
▸ Be descriptive
▸ Use real-world examples
▸ Describe the business logic
▸ Give context
@Brunty
SINGLE FEATURE PER FILE
@Brunty
Feature: As a [role] I want [feature] So that [benefit]
@Brunty
Feature: In order to [achieve value] As a [role] I want [feature]
https://lizkeogh.com/2008/05/14/rip-as-a-i-want-so-that/
@Brunty
SCENARIOS
@Brunty
SCENARIOS ARE EXAMPLES
@Brunty
EXAMPLES ARE ESSENTIAL
@Brunty
MULTIPLE SCENARIOSFEATURES CAN HAVE
@Brunty
MULTIPLE STEPSSCENARIOS HAVE…
@Brunty
GIVENPUTS THE SYSTEM IN A KNOWN STATE
@Brunty
WHENDESCRIBE A KEY ACTION
@Brunty
THENDESCRIBE AN OBSERVABLE OUTCOME
@Brunty
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
@Brunty
ANDTHERE’S ALSO…
@Brunty
BUTTHERE’S ALSO…
@Brunty
Given I have a “Large T-Shirt” product that costs £9.99
And I have an empty basket
And I am a tax-exempt customer
When I add a “Large T-Shirt” to my basket
Then I have a “Large T-Shirt” in my basket
And the basket total should be £9.99
But I do not have tax applied to my order
@Brunty
STORY STRUCTURE: THE MAKEUP OF A FEATURE FILE
@Brunty
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 have a “Large T-Shirt” in my basket
FEATURE
@Brunty
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 have a “Large T-Shirt” in my basket
@Brunty
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 have a “Large T-Shirt” in my basket
@Brunty
HOW DO DEVELOPERS WORK WITH IT?
@Brunty
STEP DEFINITIONS
@Brunty
Given I have a "Large T-Shirt" product
When I add a “Large T-Shirt” to my basket
Then I have a “Large T-Shirt” in my basket
@Brunty
ARGUMENTS
@Brunty
@Brunty
TRANSFORMERS
@Brunty
@Brunty
@Brunty
TAGS
@Brunty
@Brunty
HOOKS
@Brunty
BEFORE & AFTER SUITES, FEATURES, SCENARIOS, STEPS
HOOKS
@Brunty
@Brunty
SUITES & PROFILES
@Brunty
TEST FEATURES WITH DIFFERENT CONFIGURATIONS
SUITES ALLOW YOU TO…
@Brunty
SUITES CAN USE THE SAME FEATURE FILES. OR SUITES CAN USE DIFFERENT FEATURE FILES
FOR EXAMPLE:
@Brunty
YOU CAN USE THE SAME FEATURE FILE TO TEST DIFFERENT IMPLEMENTATIONS
WITH SUITES AND TAGS…
@Brunty
@Brunty
@Brunty
YOU CAN HAVE A UI SUITE THAT USES DIFFERENT STEP DEFINITIONS THAN A SERVICE / DOMAIN / LOWER LEVEL SUITE
FOR EXAMPLE:
@Brunty
@Brunty
@Brunty
YOU CAN CHANGE IMPLEMENTATION WITHOUT CHANGING YOUR DOCUMENTED BUSINESS RULES
WITH SUITES AND TAGS…
@Brunty
THIS IS WHERE THE POWER LIES
I FIND…
@Brunty
IMPLEMENTATION CHANGES MORE FREQUENTLY THAN BUSINESS RULES
@Brunty
WRITING A GOOD STORY
@Brunty
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 will see “Playstation 4”
And I will see £250
@Brunty
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 will have 1 product in my basket
And the basket total will be £250
BETTER STORY
@Brunty
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 will see “Playstation 4”
And I will see £250
WHAT HAPPENS WHEN THE UI CHANGES TO SAY “ADD TO CART”?
@Brunty
DON’T WRITE IMPLEMENTATION IN FEATURES
@Brunty
DEMO TIME!
@Brunty
IN SUMMARY
@Brunty
CONVERSATIONS.
CONVERSATIONS.
CONVERSATIONS.
CONVERSATIONS.
CONVERSATIONS.
@Brunty
STORIES TOLD BY REAL WORLD EXAMPLES.
USER STORIES AS REQUIREMENTS.
INVOLVE MULTIPLE STAKEHOLDERS.
WRITE FEATURES BEFORE CODE.
WRITE FEATURES WITHOUT IMPLEMENTATION.
@Brunty
BEGINNING: HAVE A CONVERSATION, CAPTURE THAT CONVERSATION
MIDDLE: AUTOMATE AND IMPLEMENT THAT CONVERSATION
END: HAPPY STAKEHOLDERS AND WELL BUILT SOFTWARE
@Brunty
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
https://cucumber.io/blog/2015/03/24/single-source-of-truth
https://github.com/Behat/Gherkin/blob/master/i18n.php#L313
@Brunty
THANKS FOR LISTENING