SlideShare a Scribd company logo
Better, faster, stronger
behat steps with
ScenarioStateBehatExtension
Behavior Driven Development
GOAL: Validate the
features/contracts, not the
implementation details
(a practical definition)
Unit tests
e2e
Acceptance
Integration tests
Somw’here
around there
From API level to GUI!
Gherkin : A Domain Specific Language to the rescue
FEATURE
Description of what should beexpected from a specific aspectof the system.
GIVEN
The system under test is
setup to match a specific and
benevolent context where the
test can be confidently
executed.
SCENARIO
A sequence of    stepsthat verify t  the
correct           behavior of the       system.
WHEN
The system under test ischallenged via its exposedpossible interactions (API,GUI, etc.).
THEN
The test runner analyze
the system under test’s
reaction and verify some
assertions.
The PHP
reference
gherkin test runner!
A Step implementation with BEHAT
State management : Where does it belong?
When the system under
test is stateful
(Like most Single Page Apps or Good’ol server
side session_start() websites)
State is chiefly handled by the system itself.
By running the steps in sequence we can
safely assume that the context in which our
steps are executed is correct and consistent.
This is the kind of environments
documentations and blogs usually use to
illustrate what they have to say.
The easy part :
Stateless Systems
(API)
By definition each interaction
with the system is one shot and
the system keeps absolutely no
track of what is going on.
Therefore, state management
must be done by the client, ie.
our tests implementations.
The not so easy:
Out of the box
solution: CONTEXTS
Behat contexts are destroyed
and recreated between each
scenario.
Then, simply use:
$this->myStateFragment = $value;
may very well be enough in most
cases.
The not so easy:But…
…sharing state fragments amongst multiple
contexts quickly becomes painful:
Strong coupling (it’s bad) is induced between
contexts (this one can be solved by writing a
specific context whose responsibility is solely
storing state fragments).
The dependency to a state fragment by a step
is hidden in the step implementation and can
not be deduced from step params.
The state management logic is dispatched in
steps implementation, it adds unnecessary
visual debt and dilute the core of the step.
OH!
The BEHAT
reference
STATE M
ANAGEM
ENT
HANDLER!
@vincentchalamon
@gorghoa
Features:
● Share state fragments with all steps
for a one (and only one) scenario;
● Inject state fragment directly to steps
functions as arguments;
● Fails fast if context is unstable
(missing state fragment dependency
for a step);
● Reduce the steps code to the bare
necessities;
● Leverage PHP type hints;
gorghoa/ScenarioStateBehatExtension
Set up : Flag a Context as state management aware
Share a state fragment
Consume a state fragment
And yeah, that is all, folks:
A simple yet effective way to
manage scenario states, letting
you to write
Better, faster, stronger
Behat steps
Thank you :)
Rodrigue Villetard
@gorghoa on twitter/github
https://rodrigue.villetard.tech
Développeur freelance
Sept. 2017,
ApéroPHP, Amiens

More Related Content

Similar to Write better, stronger, faster behat steps with ScenarioStateBehatExtension

Cucumber presentation
Cucumber presentationCucumber presentation
Cucumber presentationAkhila B
 
Software Tutorial Week1 Online 1
Software Tutorial Week1 Online 1Software Tutorial Week1 Online 1
Software Tutorial Week1 Online 1guestc154bcf
 
Unity3D Scripting: State Machine
Unity3D Scripting: State MachineUnity3D Scripting: State Machine
Unity3D Scripting: State MachineSperasoft
 
Cucumber for automated acceptance testing.pptx
Cucumber for automated acceptance testing.pptxCucumber for automated acceptance testing.pptx
Cucumber for automated acceptance testing.pptxKalhan Liyanage
 
React gsg presentation with ryan jung & elias malik
React   gsg presentation with ryan jung & elias malikReact   gsg presentation with ryan jung & elias malik
React gsg presentation with ryan jung & elias malikLama K Banna
 
A NEW INNOVATION TECHNIQUE OF STATE TRANSITION TESTING USED FOR DBT
A NEW INNOVATION TECHNIQUE OF STATE TRANSITION TESTING USED FOR DBTA NEW INNOVATION TECHNIQUE OF STATE TRANSITION TESTING USED FOR DBT
A NEW INNOVATION TECHNIQUE OF STATE TRANSITION TESTING USED FOR DBTieijjournal
 
State Test 
of Applications and Domains
State Test 
of Applications and Domains State Test 
of Applications and Domains
State Test 
of Applications and Domains Ivo Nascimento
 
Too Dependent on Shared Test Environments? Kick Start Local Workstation Testing!
Too Dependent on Shared Test Environments? Kick Start Local Workstation Testing!Too Dependent on Shared Test Environments? Kick Start Local Workstation Testing!
Too Dependent on Shared Test Environments? Kick Start Local Workstation Testing!ThoughtWorks
 
Model Driven Testing: requirements, models & test
Model Driven Testing: requirements, models & test Model Driven Testing: requirements, models & test
Model Driven Testing: requirements, models & test Gregory Solovey
 
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq PermanaJetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq PermanaDicodingEvent
 
A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)Thierry Gayet
 
Managing State With JBoss Seam
Managing State With JBoss SeamManaging State With JBoss Seam
Managing State With JBoss Seamguest74ef29
 
Modern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptxModern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptxMd Shamsul Arafin Mahtab
 
The 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web FrameworksThe 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web FrameworksKunal Ashar
 
Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7mohammad hossein Jalili
 
Virtualising Tier 1 Apps
Virtualising Tier 1 AppsVirtualising Tier 1 Apps
Virtualising Tier 1 AppsIwan Rahabok
 
Dependable Software Development in Software Engineering SE18
Dependable Software Development in Software Engineering SE18Dependable Software Development in Software Engineering SE18
Dependable Software Development in Software Engineering SE18koolkampus
 

Similar to Write better, stronger, faster behat steps with ScenarioStateBehatExtension (20)

Cucumber presentation
Cucumber presentationCucumber presentation
Cucumber presentation
 
Software Tutorial Week1 Online 1
Software Tutorial Week1 Online 1Software Tutorial Week1 Online 1
Software Tutorial Week1 Online 1
 
Jmh
JmhJmh
Jmh
 
Unity3D Scripting: State Machine
Unity3D Scripting: State MachineUnity3D Scripting: State Machine
Unity3D Scripting: State Machine
 
Cucumber for automated acceptance testing.pptx
Cucumber for automated acceptance testing.pptxCucumber for automated acceptance testing.pptx
Cucumber for automated acceptance testing.pptx
 
09 workflow
09 workflow09 workflow
09 workflow
 
React gsg presentation with ryan jung & elias malik
React   gsg presentation with ryan jung & elias malikReact   gsg presentation with ryan jung & elias malik
React gsg presentation with ryan jung & elias malik
 
A NEW INNOVATION TECHNIQUE OF STATE TRANSITION TESTING USED FOR DBT
A NEW INNOVATION TECHNIQUE OF STATE TRANSITION TESTING USED FOR DBTA NEW INNOVATION TECHNIQUE OF STATE TRANSITION TESTING USED FOR DBT
A NEW INNOVATION TECHNIQUE OF STATE TRANSITION TESTING USED FOR DBT
 
State Test 
of Applications and Domains
State Test 
of Applications and Domains State Test 
of Applications and Domains
State Test 
of Applications and Domains
 
Too Dependent on Shared Test Environments? Kick Start Local Workstation Testing!
Too Dependent on Shared Test Environments? Kick Start Local Workstation Testing!Too Dependent on Shared Test Environments? Kick Start Local Workstation Testing!
Too Dependent on Shared Test Environments? Kick Start Local Workstation Testing!
 
Model Driven Testing: requirements, models & test
Model Driven Testing: requirements, models & test Model Driven Testing: requirements, models & test
Model Driven Testing: requirements, models & test
 
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq PermanaJetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
 
A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)
 
Managing State With JBoss Seam
Managing State With JBoss SeamManaging State With JBoss Seam
Managing State With JBoss Seam
 
Jmeter From Scratch
Jmeter From ScratchJmeter From Scratch
Jmeter From Scratch
 
Modern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptxModern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptx
 
The 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web FrameworksThe 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web Frameworks
 
Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7Software engineering rogers pressman chapter 7
Software engineering rogers pressman chapter 7
 
Virtualising Tier 1 Apps
Virtualising Tier 1 AppsVirtualising Tier 1 Apps
Virtualising Tier 1 Apps
 
Dependable Software Development in Software Engineering SE18
Dependable Software Development in Software Engineering SE18Dependable Software Development in Software Engineering SE18
Dependable Software Development in Software Engineering SE18
 

Recently uploaded

The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfPipe Restoration Solutions
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationRobbie Edward Sayers
 
IT-601 Lecture Notes-UNIT-2.pdf Data Analysis
IT-601 Lecture Notes-UNIT-2.pdf Data AnalysisIT-601 Lecture Notes-UNIT-2.pdf Data Analysis
IT-601 Lecture Notes-UNIT-2.pdf Data AnalysisDr. Radhey Shyam
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectRased Khan
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxwendy cai
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfAbrahamGadissa
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-IVigneshvaranMech
 
fluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerfluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerapareshmondalnita
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxMd. Shahidul Islam Prodhan
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf884710SadaqatAli
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfKamal Acharya
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Krakówbim.edu.pl
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234AafreenAbuthahir2
 
2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edgePaco Orozco
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfKamal Acharya
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdfAhmedHussein950959
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfAyahmorsy
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacksgerogepatton
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdfKamal Acharya
 

Recently uploaded (20)

The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
IT-601 Lecture Notes-UNIT-2.pdf Data Analysis
IT-601 Lecture Notes-UNIT-2.pdf Data AnalysisIT-601 Lecture Notes-UNIT-2.pdf Data Analysis
IT-601 Lecture Notes-UNIT-2.pdf Data Analysis
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
 
fluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerfluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answer
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 

Write better, stronger, faster behat steps with ScenarioStateBehatExtension

  • 1. Better, faster, stronger behat steps with ScenarioStateBehatExtension
  • 2. Behavior Driven Development GOAL: Validate the features/contracts, not the implementation details (a practical definition) Unit tests e2e Acceptance Integration tests Somw’here around there From API level to GUI!
  • 3. Gherkin : A Domain Specific Language to the rescue
  • 4. FEATURE Description of what should beexpected from a specific aspectof the system. GIVEN The system under test is setup to match a specific and benevolent context where the test can be confidently executed. SCENARIO A sequence of    stepsthat verify t  the correct           behavior of the       system. WHEN The system under test ischallenged via its exposedpossible interactions (API,GUI, etc.). THEN The test runner analyze the system under test’s reaction and verify some assertions.
  • 7. State management : Where does it belong?
  • 8. When the system under test is stateful (Like most Single Page Apps or Good’ol server side session_start() websites) State is chiefly handled by the system itself. By running the steps in sequence we can safely assume that the context in which our steps are executed is correct and consistent. This is the kind of environments documentations and blogs usually use to illustrate what they have to say. The easy part :
  • 9. Stateless Systems (API) By definition each interaction with the system is one shot and the system keeps absolutely no track of what is going on. Therefore, state management must be done by the client, ie. our tests implementations. The not so easy:
  • 10. Out of the box solution: CONTEXTS Behat contexts are destroyed and recreated between each scenario. Then, simply use: $this->myStateFragment = $value; may very well be enough in most cases. The not so easy:But… …sharing state fragments amongst multiple contexts quickly becomes painful: Strong coupling (it’s bad) is induced between contexts (this one can be solved by writing a specific context whose responsibility is solely storing state fragments). The dependency to a state fragment by a step is hidden in the step implementation and can not be deduced from step params. The state management logic is dispatched in steps implementation, it adds unnecessary visual debt and dilute the core of the step.
  • 11. OH!
  • 13. Features: ● Share state fragments with all steps for a one (and only one) scenario; ● Inject state fragment directly to steps functions as arguments; ● Fails fast if context is unstable (missing state fragment dependency for a step); ● Reduce the steps code to the bare necessities; ● Leverage PHP type hints; gorghoa/ScenarioStateBehatExtension
  • 14. Set up : Flag a Context as state management aware
  • 15. Share a state fragment
  • 16. Consume a state fragment
  • 17. And yeah, that is all, folks: A simple yet effective way to manage scenario states, letting you to write Better, faster, stronger Behat steps
  • 18. Thank you :) Rodrigue Villetard @gorghoa on twitter/github https://rodrigue.villetard.tech Développeur freelance Sept. 2017, ApéroPHP, Amiens