@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
BEHAVIOUR DRIVEN
DEVELOPMENT
@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-GENERATION
BREAK DOWN
@Brunty
MULTIPLE-STAKEHOLDER
BREAK DOWN
@Brunty
AGILE METHODOLOGY
BREAK DOWN
@Brunty
MULTIPLE
STAKEHOLDERS
@Brunty
CONVERSATIONS
ARE KEY
@Brunty
HAVING
CONVERSATIONS >
CAPTURING
CONVERSATIONS
AUTOMATING
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
@Brunty
SO, HOW DO WE
WORK WITH THIS?
@Bruntyhttps://github.com/cucumber/cucumber/wiki/Gherkin
GHERKIN DSL
@Brunty
HUMAN READABLE
GHERKIN IS…
@Brunty
MULTI-LINGUAL SUPPORT
TOOLS CAN INCLUDE…
@Brunty
EN-PIRATE
INCLUDING
https://github.com/Behat/Gherkin/blob/master/i18n.php#L313
@Brunty
KEYWORD BASED
GHERKIN IS…
@Brunty
LINE ORIENTED
GHERKIN IS…
@Brunty
DOCUMENTATION
GHERKIN IS…
@Brunty
AUTOMATION
GHERKIN ALLOWS…
@Brunty
DEVELOPERS LOVE
AUTOMATION
@Brunty
WRITING
STORIES
@Brunty
BE DESCRIPTIVE
@Brunty
FEATURES ARE
STORIES
@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 SCENARIOS
FEATURES CAN HAVE
@Brunty
STEPS
@Brunty
MULTIPLE STEPS
SCENARIOS HAVE…
@Brunty
KEYWORDS
@Brunty
GIVEN
PUTS THE SYSTEM IN A KNOWN STATE
@Brunty
WHEN
DESCRIBE A KEY ACTION
@Brunty
THEN
DESCRIBE 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
AND
THERE’S ALSO…
@Brunty
BUT
THERE’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 & READING
https://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
@Brunty
@Brunty
@PHPem
matt@mfyu.co.uk
https://joind.in/talk/e7b59

BDD & Behat