SlideShare uma empresa Scribd logo
1 de 50
Baixar para ler offline
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

Mais conteúdo relacionado

Último

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
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
 
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
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
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
 
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
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 

Último (20)

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
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...
 
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
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
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
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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
 
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
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

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