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
240
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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.4k
Mocks and Stubs and Spies, oh my!
briangardnerdev
1
83
Take a stab at test friendly architecture
briangardnerdev
1
170
Other Decks in Technology
See All in Technology
Software Supply Chain Attackからクラウド環境を守るためにできること
lhazy
2
290
【GCC2026】大規模言語モデルを活用した内製検索サービスの社内展開や業務活用
bandainamcostudios
PRO
0
350
AI・HPC開発を支えるGPU環境の新しい選択肢 液冷GPUシステム「AquSys」の取り組み
gpuunite_official
0
160
猫付きpingコマンドを自作
uyuki234
0
280
20260817_生成AIの動向と中学校・高等学校での活用を考える_v1.00_公開用
doradora09
PRO
0
140
SmartHR Engineering Team Deck
smarthr
1
3.1k
AIのためのEthernet技術動向 (SerDes)
markunet
1
250
Digitization部 紹介資料
sansan33
PRO
2
7.7k
Head First モブプログラミング / Head First Mobprogramming
takaking22
10
12k
ハーレムエンジニアリング
kazuma777777
0
190
属人化を叩き割れ!「制作加速」と「安定化」の矛盾を打破する:8年目プロダクトが辿り着いた「ミスが起こり得ない」アセット制作フローの全貌
gree_tech
PRO
0
120
ハッカソンで入賞した話 @ Findy LT
asari194617
0
1.4k
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Ethics towards AI in product and experience design
skipperchong
2
350
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Discover your Explorer Soul
emna__ayadi
2
1.3k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
480
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Test your architecture with Archunit
thirion
2
2.3k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
170
Making Projects Easy
brettharned
120
6.7k
HDC tutorial
michielstock
2
800
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
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?