SlideShare a Scribd company logo
1 of 24
Download to read offline
Mocks, Stubs, Fakes
Dummies and Spies
Raphael Almeida
Who Am I?
Raphael Almeida
Developer since 2006
Co-founder of PHPRio, DojoRio,
RubyOnRio …
Community-a-holic
Double Objects
Type of Verifications
Best Practices
Double Objects: Simplist test
Double Objects: Awkward test
Double Objects: Types
Dummies
Fakes
Stubs
Spies
Mocks
Dummies
Used whenever we need to
pass irrelevant or never
used arguments only to
respect the method
signature
Dummies
Fakes
Simplified implementation
of a real method
Fakes
Stubs
Provide canned responses to calls made during the test
Stubs
Spies
Stubs that also record some
information based on how
they were called
Spies
Mocks
Pre-programmed objects
with expectations which
form a specification of the
calls they are expected to
receive
Mocks
Double Objects
Type of Verifications
Best Practices
Types of Verifications
State or Behaviour
Verifying State
We inspect the state of the tested object after it has been
exercised and compare it to the expected state
Verifying Behaviour
We capture the indirect output of the tested object as they
occur and compare them to the expected behavior
Double Objects
Type of Verifications
Best Practices
Best Practices
Don’t mock values
Verify the context (easy or awkward)
Use Fixtures with parsimony
Coupling test to implementations
References
https://martinfowler.com/articles/mocksArentStubs.html
https://github.com/padraic/mockery
https://github.com/php-vcr/php-vcr
XUnit Test Patterns - Gerard Meszaros
Thank you
Raphael Almeida
@raph_almeida

More Related Content

More from Raphael Almeida

Prepare-se para o próximo estágio da evolução PHP
Prepare-se para o próximo estágio da evolução PHPPrepare-se para o próximo estágio da evolução PHP
Prepare-se para o próximo estágio da evolução PHP
Raphael Almeida
 

More from Raphael Almeida (6)

Anatomia de um ataque
Anatomia de um ataqueAnatomia de um ataque
Anatomia de um ataque
 
Arquitetura de microsserviços
Arquitetura  de  microsserviçosArquitetura  de  microsserviços
Arquitetura de microsserviços
 
PaaS em php
PaaS em phpPaaS em php
PaaS em php
 
Webinar php extreme 5.3
Webinar php extreme 5.3Webinar php extreme 5.3
Webinar php extreme 5.3
 
Prepare-se para o próximo estágio da evolução PHP
Prepare-se para o próximo estágio da evolução PHPPrepare-se para o próximo estágio da evolução PHP
Prepare-se para o próximo estágio da evolução PHP
 
Aplicativos sociais
Aplicativos sociaisAplicativos sociais
Aplicativos sociais
 

Recently uploaded

Recently uploaded (20)

Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
 
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Sinoville Clinic ](+27832195400*)[🏥Abortion Pill Prices Sinoville ● Women's A...
Sinoville Clinic ](+27832195400*)[🏥Abortion Pill Prices Sinoville ● Women's A...Sinoville Clinic ](+27832195400*)[🏥Abortion Pill Prices Sinoville ● Women's A...
Sinoville Clinic ](+27832195400*)[🏥Abortion Pill Prices Sinoville ● Women's A...
 
Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements Engineering
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 

Mocks, stubs, fakes, dummies and spies