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
220
1
Share
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
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
AI時代に新卒採用、はじめました/junior-engineer-never-die
dmnlk
0
120
会社紹介資料 / Sansan Company Profile
sansan33
PRO
16
410k
Cortex Codeでデータの仕事を全部Agenticにやりきろう!
gappy50
0
300
Network Firewall Proxyで 自前プロキシを消し去ることができるのか
gusandayo
0
190
OpenClawでPM業務を自動化
knishioka
2
390
不確実性と戦いながら見積もりを作成するプロセス/mitsumori-process
hirodragon112
1
190
Cortex Code君、今日から内製化支援担当ね。
coco_se
0
270
JSTQB Expert Levelシラバス「テストマネジメント」日本語版のご紹介
ymty
0
130
OPENLOGI Company Profile for engineer
hr01
1
62k
第26回FA設備技術勉強会 - Claude/Claude_codeでデータ分析 -
happysamurai294
0
380
2026-04-02 IBM Bobオンボーディング入門
yutanonaka
0
200
ストライクウィッチーズ2期6話のエイラの行動が許せないのでPjMの観点から何をすべきだったのかを考える
ichimichi
1
110
Featured
See All Featured
Evolving SEO for Evolving Search Engines
ryanjones
0
170
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
160
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.1k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
340
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
250
Chasing Engaging Ingredients in Design
codingconduct
0
160
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
91
Designing Powerful Visuals for Engaging Learning
tmiket
1
320
Crafting Experiences
bethany
1
110
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
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?