Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Mocks and Stubs and Spies, oh my!
Search
Brian Gardner
November 05, 2017
Technology
1
220
Mocks and Stubs and Spies, oh my!
Introduction to test doubles. What they are, how they're different, and where they're used.
Brian Gardner
November 05, 2017
Tweet
Share
More Decks by Brian Gardner
See All by Brian Gardner
GoogleMap DroidCon SF 23
briangardnerdev
0
2.3k
Mocks and Stubs and Spies, oh my!
briangardnerdev
1
64
Take a stab at test friendly architecture
briangardnerdev
1
160
Other Decks in Technology
See All in Technology
2026年、サーバーレスの現在地 -「制約と戦う技術」から「当たり前の実行基盤」へ- /serverless2026
slsops
2
220
Introduction to Bill One Development Engineer
sansan33
PRO
0
360
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
3.8k
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1k
Bedrock PolicyでAmazon Bedrock Guardrails利用を強制してみた
yuu551
0
200
Webhook best practices for rock solid and resilient deployments
glaforge
1
280
Claude_CodeでSEOを最適化する_AI_Ops_Community_Vol.2__マーケティングx_AIはここまで進化した.pdf
riku_423
2
530
生成AI時代にこそ求められるSRE / SRE for Gen AI era
ymotongpoo
5
3k
茨城の思い出を振り返る ~CDKのセキュリティを添えて~ / 20260201 Mitsutoshi Matsuo
shift_evolve
PRO
1
240
SREが向き合う大規模リアーキテクチャ 〜信頼性とアジリティの両立〜
zepprix
0
440
セキュリティについて学ぶ会 / 2026 01 25 Takamatsu WordPress Meetup
rocketmartue
1
300
Kiro IDEのドキュメントを全部読んだので地味だけどちょっと嬉しい機能を紹介する
khmoryz
0
180
Featured
See All Featured
Code Review Best Practice
trishagee
74
20k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
290
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
73
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
430
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Tell your own story through comics
letsgokoyo
1
810
Odyssey Design
rkendrick25
PRO
1
490
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
Faster Mobile Websites
deanohume
310
31k
Designing for Timeless Needs
cassininazir
0
130
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
49
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Transcript
Mocks and Stubs and Spies, Oh My! Brian Gardner bit.ly/mocks-stubs-spies
Test Double Hierarchy Test Doubles Mock Fake Spy Stub Dummy
When to use Test Doubles? • System under test has
indirect inputs • System under test has indirect outputs • Slow tests*
Types of Tests Functional Unit Integration
Mocking Library
Mocks
What is a mock? • Configured with expected method calls
and parameters • Verifies method calls itself • Can return values for method calls (secondary)
Mock Types Mocks Strict Lenient
Where should you use it? Functional Unit Integration
Where should you use it? Functional Unit Integration
Where should you use it? Functional Unit Integration
Where should you use it? Functional Unit Integration
Mockito mocks
Stubs
What is a Stub? • Returns values you specify in
test • Can not return anything not specified • Does not record number of interactions
Stub Types Stubs Responder Saboteur Temporary
where should you use it? Functional Unit Integration
where should you use it? Functional Unit Integration
where should you use it? Functional Unit Integration
where should you use it? Functional Unit Integration
Mockito Stubs
Spies
What is a Spy? • Mock + Stub • Returns
values based on test configuration • Records method calls or other information • Allows you to verify method calls and parameters
where should you use it? Functional Unit Integration
where should you use it? Functional Unit Integration
where should you use it? Functional Unit Integration
where should you use it? Functional Unit Integration
Mockito Spies
Other Mockito Spies
Dummies
What is a Dummy? • Never actually used in a
test • Just fills the parameter list
Where should you use it? Functional Unit Integration
Where should you use it? Functional Unit Integration
Where should you use it? Functional Unit Integration
Where should you use it? Functional Unit Integration
Mockito dummies
Fakes
What is a Fake? • Real object specifically for test
• Replaces an object in test with a simpler/faster implementation
where should you use it? Functional Unit Integration
where should you use it? Functional Unit Integration
where should you use it? Functional Unit Integration
where should you use it? Functional Unit Integration
Mockito Fakes N/A
Recap • Use correct terms for more effective communication •
Match test doubles to the appropriate tests • Don’t over use them
Issues
Who am I? Brian Gardner @BrianGardnerAtl bit.ly/mocks-stubs-spies
Questions?