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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
66
Take a stab at test friendly architecture
briangardnerdev
1
160
Other Decks in Technology
See All in Technology
詳解 強化学習 / In-depth Guide to Reinforcement Learning
prinlab
0
300
2026-03-11 JAWS-UG 茨城 #12 改めてALBを便利に使う
masasuzu
2
400
頼れる Agentic AI を支える Datadog のオブザーバビリティ / Powering Reliable Agentic AI with Datadog Observability
aoto
PRO
0
210
システム標準化PMOから ガバメントクラウドCoEへ
techniczna
1
140
JAWS DAYS 2026 AWS知識・技術力を使って隠された旗をゲットせよ!〜出張版「ごーとんカップ」〜 解説編
kaminashi
0
110
Tebiki Engineering Team Deck
tebiki
0
27k
SRE NEXT 2026 CfP レビュアーが語る聞きたくなるプロポーザルとは?
yutakawasaki0911
1
440
Goのerror型がシンプルであることの恩恵について理解する
yamatai1212
1
240
Claude Code Skills 勉強会 (DevelersIO向けに調整済み) / claude code skills for devio
masahirokawahara
1
22k
NewSQL_ ストレージ分離と分散合意を用いたスケーラブルアーキテクチャ
hacomono
PRO
4
400
Lambda Web AdapterでLambdaをWEBフレームワーク利用する
sahou909
0
180
visionOS 開発向けの MCP / Skills をつくり続けることで XR の探究と学習を最大化
karad
1
830
Featured
See All Featured
A Soul's Torment
seathinner
5
2.5k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
160
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
290
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
310
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
410
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
400
How to Think Like a Performance Engineer
csswizardry
28
2.5k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
220
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
770
Ethics towards AI in product and experience design
skipperchong
2
230
Designing Experiences People Love
moore
143
24k
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?