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
210
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.1k
Mocks and Stubs and Spies, oh my!
briangardnerdev
1
60
Take a stab at test friendly architecture
briangardnerdev
1
150
Other Decks in Technology
See All in Technology
AWSのマルチアカウント管理 ベストプラクティス最新版 2025 / Multi-Account management on AWS best practice 2025
ohmura
3
170
開発視点でAWS Signerを考えてみよう!! ~コード署名のその先へ~
masakiokuda
3
130
Cursor AgentによるパーソナルAIアシスタント育成入門―業務のプロンプト化・MCPの活用
os1ma
7
1.7k
いつも初心者向けの記事に助けられているので得意分野では初心者向けの記事を書きます
toru_kubota
2
260
30 代子育て SRE が考える SRE ナレッジマネジメントの現在と将来
kworkdev
PRO
0
200
All You Need Is Kusa 〜Slackデータで始めるデータドリブン〜
jonnojun
0
140
Re:VIEWで書いた「Compose で Android の edge-to-edge に対応する」をRoo Codeで発表資料にしてもらった
tomoya0x00
0
260
古き良き Laravel のシステムは関数型スタイルでリファクタできるのか
leveragestech
1
620
Ops-JAWS_Organizations小ネタ3選.pdf
chunkof
2
110
Amazon S3 Tables + Amazon Athena / Apache Iceberg
okaru
0
230
バックオフィス向け toB SaaS バクラクにおけるレコメンド技術活用 / recommender-systems-in-layerx-bakuraku
yuya4
2
220
似たような課題が何度も蘇ってくるゾンビふりかえりを撲滅するため、ふりかえりのテーマをフォーカスしてもらった話 / focusing on the theme
naitosatoshi
0
370
Featured
See All Featured
A designer walks into a library…
pauljervisheath
205
24k
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.5k
Optimising Largest Contentful Paint
csswizardry
36
3.2k
BBQ
matthewcrist
88
9.6k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
Adopting Sorbet at Scale
ufuk
76
9.3k
Scaling GitHub
holman
459
140k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
34
2.2k
We Have a Design System, Now What?
morganepeng
52
7.5k
Code Review Best Practice
trishagee
67
18k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
178
52k
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?