SlideShare a Scribd company logo
1 of 23
Download to read offline
Behavior-Driven
Development with
Behat and Gherkin
Marcus Moore
1
Why Test?
2
Types of Tests
• Unit
• Integration
3
Test-Driven
Development
4
Behavior-Driven
Development
5
What is Behavior-Driven
Development?
• Behavior-Driven Development (BDD) is an extension of Test-
Driven Development (TDD) that focuses on delivering
software that matters.
6
Why?
• TDD doesn't necessarily mean you built the right thing
• Communication is hard
• Initial requirements document (sometimes)
• Email threads / Slack
• Bug reports
• Github Issues
• Assumptions are made about the requirement
7
For Example...
"Users can RSVP for an event if it is not at capacity"
• What if it is at capacity?
• "Put them on a wait-list"
8
Gherkin
• Common and human-readable language between clients,
developers, testers, etc
• Write requirements in a way that can be run by a test-runner
9
Gherkin
• Clients and developers work off in the same files for
requirements
• Clients are continually signing off on what developers are
working on (if all goes well)
• Maybe adding their own requirements
10
Feature Files
• Contain a Story
• Easily understandable
11
Feature: one line describing the story
Narrative:
As a [role]
I want [feature]
So that [benefit]
Scenario: [description]
Given [context]
And [some more context]...
When [event]
Then [outcome]
And [another outcome]...
12
The Steps of a Test
1. Given
2. When
3. Then
13
Feature: Creating Events
As an owner of a group
I need to be able to create events
So other users can meet up with me
Rules:
- Only owners can create events for a group
- Events cannot be created in the past
- Events are private until published
Scenario: A non-owner tries to create an event for a group
Given there is an existing group
When a user that is not an owner tries to create an event for the group
Then the user should be rejected with an authorization error
And the event should not exist
Scenario: Create an event with invalid attributes
# ...
Scenario: An owner tries to create an event in the past
# ...
Scenario: Create an event
Given there is an existing group
When the owner tries to create an event for the group
Then the owner should see a success message
And the event should exist
And the event should be private
14
The Steps of a Test
1. Given some context
2. When something happens
3. Then there should be a specific outcome
15
Example...
16
Checklist
• append-snippets
• --suite
• variables
• BaseContext
• BeforeScenarioScope / AfterScenarioScope
17
Scenario Backgrounds
Background:
Given there is an existing group
18
Scenario Outlines
Scenario Outline: Eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |
19
Tables
Given there are users:
| username | password | email |
| everzet | 123456 | everzet@knplabs.com |
| fabpot | 22@222 | fabpot@symfony.com |
20
Extensions
• There's a lot...
• Mink
21
Caveats...
• Debugging isn't as nice
• Code coverage isn't a focus
22
Resources
• What is Gherkin – BDD Language?
• What's in a Story?
• The Truth about BDD
23

More Related Content

Similar to Behavior driven development with Behat and Gherkin

Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Ortus Solutions, Corp
 
Refactoring Legacy Code - true story
Refactoring Legacy Code - true storyRefactoring Legacy Code - true story
Refactoring Legacy Code - true story
Aki Salmi
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
Dave Haeffner
 
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
Lucas Jellema
 
Bootstrapping your startup & building it lean: stop wasting time
Bootstrapping your startup & building it lean: stop wasting timeBootstrapping your startup & building it lean: stop wasting time
Bootstrapping your startup & building it lean: stop wasting time
Joel Gascoigne
 
An Overview of automated testing (1)
An Overview of automated testing (1)An Overview of automated testing (1)
An Overview of automated testing (1)
Rodrigo Lopes
 
A Study of the Characteristics of Developers′ Activities in GitHub
A Study of the Characteristics of Developers′ Activities in GitHubA Study of the Characteristics of Developers′ Activities in GitHub
A Study of the Characteristics of Developers′ Activities in GitHub
奈良先端大 情報科学研究科
 

Similar to Behavior driven development with Behat and Gherkin (20)

Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven Development
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
 
Refactoring Legacy Code - true story
Refactoring Legacy Code - true storyRefactoring Legacy Code - true story
Refactoring Legacy Code - true story
 
Get lean tutorial
Get lean tutorialGet lean tutorial
Get lean tutorial
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
 
Random thoughts and dev practices / advices to build a great product
Random thoughts and dev practices / advices to build a great productRandom thoughts and dev practices / advices to build a great product
Random thoughts and dev practices / advices to build a great product
 
Functional Tests. PHP Unconf 2016
Functional Tests. PHP Unconf 2016Functional Tests. PHP Unconf 2016
Functional Tests. PHP Unconf 2016
 
How should we change our approach to content creation to fit agile ways of wo...
How should we change our approach to content creation to fit agile ways of wo...How should we change our approach to content creation to fit agile ways of wo...
How should we change our approach to content creation to fit agile ways of wo...
 
Continuous feature-development
Continuous feature-developmentContinuous feature-development
Continuous feature-development
 
Owasp tds
Owasp tdsOwasp tds
Owasp tds
 
Learn Learning + Prototype Testing
Learn Learning + Prototype TestingLearn Learning + Prototype Testing
Learn Learning + Prototype Testing
 
Successfully Implementing BDD in an Agile World
Successfully Implementing BDD in an Agile WorldSuccessfully Implementing BDD in an Agile World
Successfully Implementing BDD in an Agile World
 
Specification by example
Specification by exampleSpecification by example
Specification by example
 
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
 
Bootstrapping your startup & building it lean: stop wasting time
Bootstrapping your startup & building it lean: stop wasting timeBootstrapping your startup & building it lean: stop wasting time
Bootstrapping your startup & building it lean: stop wasting time
 
An Overview of automated testing (1)
An Overview of automated testing (1)An Overview of automated testing (1)
An Overview of automated testing (1)
 
UsabilityMatters_Usability_Testing_Introduction_Workshop
UsabilityMatters_Usability_Testing_Introduction_WorkshopUsabilityMatters_Usability_Testing_Introduction_Workshop
UsabilityMatters_Usability_Testing_Introduction_Workshop
 
A Study of the Characteristics of Developers′ Activities in GitHub
A Study of the Characteristics of Developers′ Activities in GitHubA Study of the Characteristics of Developers′ Activities in GitHub
A Study of the Characteristics of Developers′ Activities in GitHub
 

Recently uploaded

Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 

Recently uploaded (20)

WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 

Behavior driven development with Behat and Gherkin

  • 3. Types of Tests • Unit • Integration 3
  • 6. What is Behavior-Driven Development? • Behavior-Driven Development (BDD) is an extension of Test- Driven Development (TDD) that focuses on delivering software that matters. 6
  • 7. Why? • TDD doesn't necessarily mean you built the right thing • Communication is hard • Initial requirements document (sometimes) • Email threads / Slack • Bug reports • Github Issues • Assumptions are made about the requirement 7
  • 8. For Example... "Users can RSVP for an event if it is not at capacity" • What if it is at capacity? • "Put them on a wait-list" 8
  • 9. Gherkin • Common and human-readable language between clients, developers, testers, etc • Write requirements in a way that can be run by a test-runner 9
  • 10. Gherkin • Clients and developers work off in the same files for requirements • Clients are continually signing off on what developers are working on (if all goes well) • Maybe adding their own requirements 10
  • 11. Feature Files • Contain a Story • Easily understandable 11
  • 12. Feature: one line describing the story Narrative: As a [role] I want [feature] So that [benefit] Scenario: [description] Given [context] And [some more context]... When [event] Then [outcome] And [another outcome]... 12
  • 13. The Steps of a Test 1. Given 2. When 3. Then 13
  • 14. Feature: Creating Events As an owner of a group I need to be able to create events So other users can meet up with me Rules: - Only owners can create events for a group - Events cannot be created in the past - Events are private until published Scenario: A non-owner tries to create an event for a group Given there is an existing group When a user that is not an owner tries to create an event for the group Then the user should be rejected with an authorization error And the event should not exist Scenario: Create an event with invalid attributes # ... Scenario: An owner tries to create an event in the past # ... Scenario: Create an event Given there is an existing group When the owner tries to create an event for the group Then the owner should see a success message And the event should exist And the event should be private 14
  • 15. The Steps of a Test 1. Given some context 2. When something happens 3. Then there should be a specific outcome 15
  • 17. Checklist • append-snippets • --suite • variables • BaseContext • BeforeScenarioScope / AfterScenarioScope 17
  • 19. Scenario Outlines Scenario Outline: Eating Given there are <start> cucumbers When I eat <eat> cucumbers Then I should have <left> cucumbers Examples: | start | eat | left | | 12 | 5 | 7 | | 20 | 5 | 15 | 19
  • 20. Tables Given there are users: | username | password | email | | everzet | 123456 | everzet@knplabs.com | | fabpot | 22@222 | fabpot@symfony.com | 20
  • 21. Extensions • There's a lot... • Mink 21
  • 22. Caveats... • Debugging isn't as nice • Code coverage isn't a focus 22
  • 23. Resources • What is Gherkin – BDD Language? • What's in a Story? • The Truth about BDD 23