SlideShare a Scribd company logo
BDD with Behat
Rob Ingram
Image credit: J Williams
Outline
Narrative
Background
Scenarios
Outline
In order to <achieve a business goal>
As a <stakeholder>
I want <something>
Outline
Feature: store locator
In order to shop at the closest store
As a customer
I want to search for stores in my city
Alternative format
Feature: store locator
As a customer
I want to search for stores in my city
So that I can shop at the closest store
Scenario
Given <a context>
When <something happens>
Then <I expect some outcomes>
Scenario
Scenario: search by city name
Given I am on the homepage
When I fill in "location" with "Christchurch"
And I press "Locate"
Then I should be on the “Store Locator” page
And I should see “Kathmandu Christchurch CBD Re:START”
And I should see “0.2km”
Scenario
Scenario: search by city name
Given I am on the homepage
When I fill in "location" with "Christchurch"
And I press “Locate"
Then I should be on the “Store Locator” page
And I should see the following store results:
| name | distance |
| Kathmandu Christchurch CBD Re:START | 0.2km |
| Kathmandu Tower Junction | 2.5km |
Background
Background:
Given I am logged in
Image credit: PittCaleb
BDD with Behat and PHPSpec
PHPSpec
<?php
namespace spec;
use PhpSpecObjectBehavior;
class MarkdownSpec extends ObjectBehavior
{
function it_converts_plain_text_to_html_paragraphs()
{
$this->toHtml("Hi, there")->shouldReturn("<p>Hi,
there</p>");
}
}
Live coding
Kinda
BDD with Behat and PHPSpec
Image credit: @joefoodie
Links
Behat: http://docs.behat.org/en/v3.0/
Behat Silverstripe: https://github.com/silverstripe-
labs/silverstripe-behat-extension
PHPSpec: http://www.phpspec.net/en/stable/

More Related Content

PPTX
My name is biplob
PDF
Small talk online 2
DOCX
PPTX
Outsourcing for small businesses
PPTX
KEY
Retargeting 101 - Presentation at 500 startups
PPTX
Keep on talking in the free world
PPTX
Experience Agile Programming - Kiev
My name is biplob
Small talk online 2
Outsourcing for small businesses
Retargeting 101 - Presentation at 500 startups
Keep on talking in the free world
Experience Agile Programming - Kiev

Recently uploaded (20)

PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
innovation process that make everything different.pptx
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Internet___Basics___Styled_ presentation
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
Introduction to the IoT system, how the IoT system works
PPTX
international classification of diseases ICD-10 review PPT.pptx
PPTX
Introduction to Information and Communication Technology
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Cloud-Scale Log Monitoring _ Datadog.pdf
522797556-Unit-2-Temperature-measurement-1-1.pptx
innovation process that make everything different.pptx
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Internet___Basics___Styled_ presentation
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
Decoding a Decade: 10 Years of Applied CTI Discipline
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Introuction about ICD -10 and ICD-11 PPT.pptx
Tenda Login Guide: Access Your Router in 5 Easy Steps
WebRTC in SignalWire - troubleshooting media negotiation
Introduction to the IoT system, how the IoT system works
international classification of diseases ICD-10 review PPT.pptx
Introduction to Information and Communication Technology
RPKI Status Update, presented by Makito Lay at IDNOG 10
Module 1 - Cyber Law and Ethics 101.pptx
Power Point - Lesson 3_2.pptx grad school presentation
SAP Ariba Sourcing PPT for learning material
PptxGenJS_Demo_Chart_20250317130215833.pptx
Ad
Ad

BDD with Behat and PHPSpec

Editor's Notes

  • #3: 1. What is BDD - Extension of TDD to cover the entire development process - Associated with agile methodologies - Encourage a collaborative process with all stakeholders - Requirements generated by cross-functional teams, BA, developers, tester involved early on - shared understanding 2. "Build the software right", "Build the right software" - Each proposed feature should have a specific business value that everyone involved buys into - Examples produced in a standard format that can be understood by everyone - This is an _executable specifications_ - And living documentation of the behaviour of the system that is PROVEN 3. Language of the spec is often referred to as Gherkin - Best know through Ruby tool Cucumber - TDD actually came out of the Java community (JBehave) - All stories/features refer to a user (persona?) and the business value of the feature to that user - Stories are the basis for discussion in an iterative process
  • #4: At least a outline (high level) and number of scenarios (detail of what happens) Optional narrative and background
  • #5: 2 usual formats for outline
  • #8: All of these can be extended with “And”
  • #9: Each line is a “step”
  • #11: Set up conditions to be executed before each scenario
  • #12: Beat - PHP version of a suite of tools Drives the site as a user would. Goutte driver, Selenium or headless for JS Each line becomes a step in a context file Executes known steps Provides outline for any unknown tests Match regexp Mink - common web steps and helpers
  • #13: When a feature fails, if it requires logic, drop down to standard TDD process then back up once green
  • #16: SS behat extension - Access SS classes from Behat context - Set up and reset test database - YAML fixtures in Behat scenarios
  • #17: DB JS/AJAX timing Slow, especially when driving a browser for JS Targeting HTML elements - temptation to be too imperative rather than declarative