SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Downloaden Sie, um offline zu lesen
Behavior Driven
Development and
Laravel
1
About Me
• Marcus Moore
• San Diego, CA
• Diego Dev Group
• San Diego PHP User Group co-organizer
2
Overview
• My history with Behavior Driven Development
• Behavior Driven Development
• Behavior Driven Development and Laravel
3
My History with BDD
• When I worked at a small school
• Gathering requirements was easy!
4
My History with BDD
• Working for an agency...
• Requirement gathering got harder...
• Many clients with many communication styles
• "Who has solved this?"
5
Behavior Driven Development
• Extension of Test Driven Development (TDD)
• BDD works closely with Unit Testing
• BDD is not about testing
• Helps you build the right thing
6
Communication is hard
• Ambiguities arise
• Assumptions are made
• Rework becomes inevitable
7
BDD's Goals
• Close communication gap between all stakeholders using
real examples
• Establish a shared understanding of the desired outcome
• Eliminate "rework"
8
Three Steps
1. Discovery
2. Formulation
3. Automation
9
Discovery
• Most important part!
• Enables stakeholders to have focused conversations
• Fills knowledge gaps
• Develops an understanding of how the software should
function using real examples
10
Methods of Discovery
• Discovery Workshops
• Example Mapping
• Event Storming
• etc...
11
Discovery Workshops
• AKA the Three Amigos
• Short and frequent meetings
• Different people with different perspectives
12
Three Amigos
1. Business Person (Product Owner)
• Determines "what"
• Expresses the user stories
2. Developer
• Determines "how"
• Looks for details and potential roadblocks
3. Quality Assurance
• Come up with the "what if's"
• Tries to determine what will break
13
Discovery Results
• Complete shared understanding
• Concrete examples
14
Formulation
• Documentation of the concrete examples
• Written in natural language syntax
• Readable by humans and software
• .feature files
• Gherkin
15
Gherkin
• Tells the Story via a narrative
• Easy for non-technical people to read
16
Feature: Requesting rides
As a verified user
I want to request a ride
So that I can get to my destination on time
Rule: Unverified users cannot request rides
Rule: User cannot request ride for more than 5 people
Scenario: A user requests a ride for 4 people
Given I am a verified user
And there is a van with 5 seats nearby
And there is a car with 3 seats next to me
When I request a ride for 4 people
Then I should see I am being connected to the van
17
Given - Set the state of the world
Given I am a verified user
And there is a van with 5 seats nearby
And there is a car with 3 seats next to me
18
When - Interact with the application
When I request a ride for 4 people
19
Then - Check the outcome of the interaction
Then I should see I am being connected to the van
20
Feature: Requesting rides
As a verified user
I want to request a ride
So that I can get to my destination on time
Rule: Unverified users cannot request rides
Rule: User cannot request ride for more than 5 people
Scenario: A user requests a ride for 4 people
Given I am a verified user
And there is a van with 5 seats nearby
And there is a car with 3 seats next to me
When I request a ride for 4 people
Then I should see I am being connected to the van
21
Formulation Results
• Common terminology solidified
• Shared understanding is documented in feature files
• New people can understand the application
22
Automation
• Start to implement the features with BDD and TDD
• Double-Loop Workflow
• Implement the features with Behat
23
Behat
• The go-to BDD Framework for PHP
• Implementation of Cucumber
24
Laravel and Behat
25
Installation and Setup
• Install via Composer
• vendor/bin/behat !"init
• Add your feature files to /features
• vendor/bin/behat !"append-snippets
26
Feature: Requesting rides
As a verified user
I want to request a ride
So that I can get to my destination on time
Rule: Unverified users cannot request rides
Rule: User cannot request ride for more than 5 people
Scenario: A user requests a ride for 4 people
Given I am a verified user
And there is a van with 5 seats nearby
And there is a car with 3 seats next to me
When I request a ride for 4 people
Then I should see I am being connected to the van
27
/**
* @Given I am a verified user
"#
public function iAmAVerifiedUser()
{
throw new PendingException();
}
28
/**
* @Given I am a verified user
"#
public function iAmAVerifiedUser()
{
$this"$actingUser = factory(User"%class)
"$state('verified')
"$create();
$this"$userLocation = [
'latitude' "& '32.7',
'longitude' "& '-117.1',
];
}
29
class FeatureContext implements Context
{
public function !"construct()
{
}
}
30
class BaseContext extends TestCase implements Context
{
use CreatesApplication;
public function !"construct()
{
putenv('APP_ENV=testing');
parent!#!"construct();
$this!$setUp();
$this!$withoutExceptionHandling();
}
/** @BeforeScenario !%
public function before(BeforeScenarioScope $scope)
{
$this!$artisan('migrate:fresh');
}
}
31
/**
* @Given I am a verified user
"#
public function iAmAVerifiedUser()
{
$this"$actingUser = factory(User"%class)
"$state('verified')
"$create();
$this"$userLocation = [
'latitude' "& '32.7',
'longitude' "& '-117.1',
];
}
32
/**
* @And there is a van with :arg1 seats nearby
!"
public function thereIsAVanWithSeatsNearby($arg1)
{
throw new PendingException();
}
33
And there is a van with 5 seats nearby
34
/**
* @And there is a van with :arg1 seats nearby
!"
public function thereIsAVanWithSeatsNearby($arg1)
{
throw new PendingException();
}
35
/**
* @And there is a van with :numberOfSeats seats nearby
!"
public function thereIsAVanWithSeatsNearby($numberOfSeats)
{
$this!#createVan($numberOfSeats, $distanceFromUser = 3);
}
36
/**
* @And there is a car with :numberOfSeats seats next to me
!"
public function thereIsACarWithSeatsNextToMe($numberOfSeats)
{
$this!#createCar($numberOfSeats, $distanceFromUser = 1);
}
37
$this!"createVan($numberOfSeats, $distanceFromUser = 3);
$this!"createCar($numberOfSeats, $distanceFromUser = 1);
38
Scenario: A user requests a ride for 4 people
Given I am a verified user
And there is a van with 5 seats nearby
And there is a car with 3 seats next to me
When I request a ride for 4 people
Then I should see I am being connected to the van
39
Scenario: A user requests a ride for 4 people
Given I am a verified user
And there is a "van" with "5" seats "nearby"
And there is a "car" with "3" seats "next to me"
When I request a ride for 4 people
Then I should see I am being connected to the van
40
/**
* @Given there is a :arg1 with :arg2 seats :arg3
!"
public function thereIsAWithSeats($arg1, $arg2, $arg3)
{
throw new PendingException();
}
41
/**
* @Given there is a :typeOfVehicle with :numberOfSeats seats :distanceFromUser
!"
public function thereIsAWithSeatsNearby($typeOfVehicle, $numberOfSeats, $distanceFromUser)
{
$distance = 3;
if ($distanceFromUser !!# 'next to me') {
$distance = 1;
}
$this!$vehicles[$typeOfVehicle] = $this!$createVehicle($typeOfVehicle, $numberOfSeats, $distance);
}
42
/**
* @When I request a ride for :numberOfPeople people
!"
public function iRequestARideForPeople($numberOfPeople)
{
$this!#response = $this!#actingAs($this!#actingUser)
!#json(
'POST',
'/api/get-ride',
[
'location' !% $this!#userLocation,
'number_of_seats' !% $numberOfPeople
]
);
}
43
!" Controller does some work to match user and driver
!" Good time to TDD a service!
return response()!#json([
'message' !$ $closestVehicle!#driver . ' will pick you up soon!',
]);
44
/**
* @Then I should see I am being connected to the van
!"
public function iShouldSeeIAmBeingConnectedToTheVan()
{
$messageFromResponse = $this!#response!#decodeResponseJson('message');
$nameOfVanDriver = $this!#vehicles['van']['driver'];
$this!#assertTrue(Str!$contains($messageFromResponse, $nameOfVanDriver));
}
45
Repeat the cycle for the rest of the scenarios...
46
Also... Mink
47
Automation Results
• Real-world examples drove the development of the
application
• The application is tested on multiple levels
48
So...
1. Discovery
2. Formulation
3. Automation
4.
! "
49
Thank you
• bit.ly/laracon-au-bdd
• twitter.com/marcusamoore
50

Weitere ähnliche Inhalte

Was ist angesagt?

Ppt pengenalan jquery
Ppt pengenalan jqueryPpt pengenalan jquery
Ppt pengenalan jquerymutia902
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryZeeshan Khan
 
Clean architecture
Clean architectureClean architecture
Clean architectureandbed
 
Railway Oriented Programming
Railway Oriented ProgrammingRailway Oriented Programming
Railway Oriented ProgrammingScott Wlaschin
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Dilouar Hossain
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesRoman Elizarov
 
The Secrets of Hexagonal Architecture
The Secrets of Hexagonal ArchitectureThe Secrets of Hexagonal Architecture
The Secrets of Hexagonal ArchitectureNicolas Carlo
 
CQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java DevelopersCQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java DevelopersMarkus Eisele
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event LoopDesignveloper
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6Rob Eisenberg
 
Hands-On Java web passando por Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...
Hands-On Java web passando por  Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...Hands-On Java web passando por  Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...
Hands-On Java web passando por Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...Mario Jorge Pereira
 
NgRx 101 Connect.Tech 2019
NgRx 101   Connect.Tech 2019NgRx 101   Connect.Tech 2019
NgRx 101 Connect.Tech 2019Sergio Brito
 
.NET MAUI with .NET 6 (December 2021, Preview 10)
.NET MAUI with .NET 6 (December 2021, Preview 10).NET MAUI with .NET 6 (December 2021, Preview 10)
.NET MAUI with .NET 6 (December 2021, Preview 10)Alex Pshul
 
Cypress-vs-Playwright: Let the Code Speak
Cypress-vs-Playwright: Let the Code SpeakCypress-vs-Playwright: Let the Code Speak
Cypress-vs-Playwright: Let the Code SpeakApplitools
 

Was ist angesagt? (20)

jQuery
jQueryjQuery
jQuery
 
Ppt pengenalan jquery
Ppt pengenalan jqueryPpt pengenalan jquery
Ppt pengenalan jquery
 
laravel.pptx
laravel.pptxlaravel.pptx
laravel.pptx
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Railway Oriented Programming
Railway Oriented ProgrammingRailway Oriented Programming
Railway Oriented Programming
 
React JS
React JSReact JS
React JS
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
webworkers
webworkerswebworkers
webworkers
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin Coroutines
 
The Secrets of Hexagonal Architecture
The Secrets of Hexagonal ArchitectureThe Secrets of Hexagonal Architecture
The Secrets of Hexagonal Architecture
 
CQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java DevelopersCQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java Developers
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
Hands-On Java web passando por Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...
Hands-On Java web passando por  Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...Hands-On Java web passando por  Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...
Hands-On Java web passando por Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...
 
NgRx 101 Connect.Tech 2019
NgRx 101   Connect.Tech 2019NgRx 101   Connect.Tech 2019
NgRx 101 Connect.Tech 2019
 
.NET MAUI with .NET 6 (December 2021, Preview 10)
.NET MAUI with .NET 6 (December 2021, Preview 10).NET MAUI with .NET 6 (December 2021, Preview 10)
.NET MAUI with .NET 6 (December 2021, Preview 10)
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
 
Cypress-vs-Playwright: Let the Code Speak
Cypress-vs-Playwright: Let the Code SpeakCypress-vs-Playwright: Let the Code Speak
Cypress-vs-Playwright: Let the Code Speak
 

Kürzlich hochgeladen

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 

Kürzlich hochgeladen (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 

Behavior Driven Development and Laravel

  • 2. About Me • Marcus Moore • San Diego, CA • Diego Dev Group • San Diego PHP User Group co-organizer 2
  • 3. Overview • My history with Behavior Driven Development • Behavior Driven Development • Behavior Driven Development and Laravel 3
  • 4. My History with BDD • When I worked at a small school • Gathering requirements was easy! 4
  • 5. My History with BDD • Working for an agency... • Requirement gathering got harder... • Many clients with many communication styles • "Who has solved this?" 5
  • 6. Behavior Driven Development • Extension of Test Driven Development (TDD) • BDD works closely with Unit Testing • BDD is not about testing • Helps you build the right thing 6
  • 7. Communication is hard • Ambiguities arise • Assumptions are made • Rework becomes inevitable 7
  • 8. BDD's Goals • Close communication gap between all stakeholders using real examples • Establish a shared understanding of the desired outcome • Eliminate "rework" 8
  • 9. Three Steps 1. Discovery 2. Formulation 3. Automation 9
  • 10. Discovery • Most important part! • Enables stakeholders to have focused conversations • Fills knowledge gaps • Develops an understanding of how the software should function using real examples 10
  • 11. Methods of Discovery • Discovery Workshops • Example Mapping • Event Storming • etc... 11
  • 12. Discovery Workshops • AKA the Three Amigos • Short and frequent meetings • Different people with different perspectives 12
  • 13. Three Amigos 1. Business Person (Product Owner) • Determines "what" • Expresses the user stories 2. Developer • Determines "how" • Looks for details and potential roadblocks 3. Quality Assurance • Come up with the "what if's" • Tries to determine what will break 13
  • 14. Discovery Results • Complete shared understanding • Concrete examples 14
  • 15. Formulation • Documentation of the concrete examples • Written in natural language syntax • Readable by humans and software • .feature files • Gherkin 15
  • 16. Gherkin • Tells the Story via a narrative • Easy for non-technical people to read 16
  • 17. Feature: Requesting rides As a verified user I want to request a ride So that I can get to my destination on time Rule: Unverified users cannot request rides Rule: User cannot request ride for more than 5 people Scenario: A user requests a ride for 4 people Given I am a verified user And there is a van with 5 seats nearby And there is a car with 3 seats next to me When I request a ride for 4 people Then I should see I am being connected to the van 17
  • 18. Given - Set the state of the world Given I am a verified user And there is a van with 5 seats nearby And there is a car with 3 seats next to me 18
  • 19. When - Interact with the application When I request a ride for 4 people 19
  • 20. Then - Check the outcome of the interaction Then I should see I am being connected to the van 20
  • 21. Feature: Requesting rides As a verified user I want to request a ride So that I can get to my destination on time Rule: Unverified users cannot request rides Rule: User cannot request ride for more than 5 people Scenario: A user requests a ride for 4 people Given I am a verified user And there is a van with 5 seats nearby And there is a car with 3 seats next to me When I request a ride for 4 people Then I should see I am being connected to the van 21
  • 22. Formulation Results • Common terminology solidified • Shared understanding is documented in feature files • New people can understand the application 22
  • 23. Automation • Start to implement the features with BDD and TDD • Double-Loop Workflow • Implement the features with Behat 23
  • 24. Behat • The go-to BDD Framework for PHP • Implementation of Cucumber 24
  • 26. Installation and Setup • Install via Composer • vendor/bin/behat !"init • Add your feature files to /features • vendor/bin/behat !"append-snippets 26
  • 27. Feature: Requesting rides As a verified user I want to request a ride So that I can get to my destination on time Rule: Unverified users cannot request rides Rule: User cannot request ride for more than 5 people Scenario: A user requests a ride for 4 people Given I am a verified user And there is a van with 5 seats nearby And there is a car with 3 seats next to me When I request a ride for 4 people Then I should see I am being connected to the van 27
  • 28. /** * @Given I am a verified user "# public function iAmAVerifiedUser() { throw new PendingException(); } 28
  • 29. /** * @Given I am a verified user "# public function iAmAVerifiedUser() { $this"$actingUser = factory(User"%class) "$state('verified') "$create(); $this"$userLocation = [ 'latitude' "& '32.7', 'longitude' "& '-117.1', ]; } 29
  • 30. class FeatureContext implements Context { public function !"construct() { } } 30
  • 31. class BaseContext extends TestCase implements Context { use CreatesApplication; public function !"construct() { putenv('APP_ENV=testing'); parent!#!"construct(); $this!$setUp(); $this!$withoutExceptionHandling(); } /** @BeforeScenario !% public function before(BeforeScenarioScope $scope) { $this!$artisan('migrate:fresh'); } } 31
  • 32. /** * @Given I am a verified user "# public function iAmAVerifiedUser() { $this"$actingUser = factory(User"%class) "$state('verified') "$create(); $this"$userLocation = [ 'latitude' "& '32.7', 'longitude' "& '-117.1', ]; } 32
  • 33. /** * @And there is a van with :arg1 seats nearby !" public function thereIsAVanWithSeatsNearby($arg1) { throw new PendingException(); } 33
  • 34. And there is a van with 5 seats nearby 34
  • 35. /** * @And there is a van with :arg1 seats nearby !" public function thereIsAVanWithSeatsNearby($arg1) { throw new PendingException(); } 35
  • 36. /** * @And there is a van with :numberOfSeats seats nearby !" public function thereIsAVanWithSeatsNearby($numberOfSeats) { $this!#createVan($numberOfSeats, $distanceFromUser = 3); } 36
  • 37. /** * @And there is a car with :numberOfSeats seats next to me !" public function thereIsACarWithSeatsNextToMe($numberOfSeats) { $this!#createCar($numberOfSeats, $distanceFromUser = 1); } 37
  • 38. $this!"createVan($numberOfSeats, $distanceFromUser = 3); $this!"createCar($numberOfSeats, $distanceFromUser = 1); 38
  • 39. Scenario: A user requests a ride for 4 people Given I am a verified user And there is a van with 5 seats nearby And there is a car with 3 seats next to me When I request a ride for 4 people Then I should see I am being connected to the van 39
  • 40. Scenario: A user requests a ride for 4 people Given I am a verified user And there is a "van" with "5" seats "nearby" And there is a "car" with "3" seats "next to me" When I request a ride for 4 people Then I should see I am being connected to the van 40
  • 41. /** * @Given there is a :arg1 with :arg2 seats :arg3 !" public function thereIsAWithSeats($arg1, $arg2, $arg3) { throw new PendingException(); } 41
  • 42. /** * @Given there is a :typeOfVehicle with :numberOfSeats seats :distanceFromUser !" public function thereIsAWithSeatsNearby($typeOfVehicle, $numberOfSeats, $distanceFromUser) { $distance = 3; if ($distanceFromUser !!# 'next to me') { $distance = 1; } $this!$vehicles[$typeOfVehicle] = $this!$createVehicle($typeOfVehicle, $numberOfSeats, $distance); } 42
  • 43. /** * @When I request a ride for :numberOfPeople people !" public function iRequestARideForPeople($numberOfPeople) { $this!#response = $this!#actingAs($this!#actingUser) !#json( 'POST', '/api/get-ride', [ 'location' !% $this!#userLocation, 'number_of_seats' !% $numberOfPeople ] ); } 43
  • 44. !" Controller does some work to match user and driver !" Good time to TDD a service! return response()!#json([ 'message' !$ $closestVehicle!#driver . ' will pick you up soon!', ]); 44
  • 45. /** * @Then I should see I am being connected to the van !" public function iShouldSeeIAmBeingConnectedToTheVan() { $messageFromResponse = $this!#response!#decodeResponseJson('message'); $nameOfVanDriver = $this!#vehicles['van']['driver']; $this!#assertTrue(Str!$contains($messageFromResponse, $nameOfVanDriver)); } 45
  • 46. Repeat the cycle for the rest of the scenarios... 46
  • 48. Automation Results • Real-world examples drove the development of the application • The application is tested on multiple levels 48
  • 49. So... 1. Discovery 2. Formulation 3. Automation 4. ! " 49
  • 50. Thank you • bit.ly/laracon-au-bdd • twitter.com/marcusamoore 50