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
65
Take a stab at test friendly architecture
briangardnerdev
1
160
Other Decks in Technology
See All in Technology
男(監査)はつらいよ - Policy as CodeからAIエージェントへ
ken5scal
5
730
Digitization部 紹介資料
sansan33
PRO
1
7k
ソフトウェアアーキテクトのための意思決定術: Create Decision Readiness—The Real Skill Behind Architectural Decision
snoozer05
PRO
30
9k
Kiro のクレジットを使い切る!
otanikohei2023
0
110
生成AI活用によるPRレビュー改善の歩み
lycorptech_jp
PRO
5
2.1k
管理者向けGitHub Enterpriseの運用Tips紹介: 人にもAIにも優しいプラットフォームづくり
yuriemori
0
110
入門DBSC
ynojima
0
130
20260305_【白金鉱業】分析者が地理情報を武器にするための軽量なアドホック分析環境
yucho147
1
170
Eight Engineering Unit 紹介資料
sansan33
PRO
1
6.9k
A Gentle Introduction to Transformers
keio_smilab
PRO
1
120
Claude Codeの進化と各機能の活かし方
oikon48
12
3.4k
Oracle Cloud Infrastructure:2026年2月度サービス・アップデート
oracle4engineer
PRO
0
220
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
380
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
How to make the Groovebox
asonas
2
2k
For a Future-Friendly Web
brad_frost
183
10k
GraphQLの誤解/rethinking-graphql
sonatard
75
11k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
140
How Software Deployment tools have changed in the past 20 years
geshan
0
32k
Become a Pro
speakerdeck
PRO
31
5.8k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Building AI with AI
inesmontani
PRO
1
760
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?