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
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.4k
Mocks and Stubs and Spies, oh my!
briangardnerdev
1
69
Take a stab at test friendly architecture
briangardnerdev
1
160
Other Decks in Technology
See All in Technology
Python開発環境にハーネス適用を検討する
yuuka51
1
510
The Making of AI Chips
pfn
PRO
0
770
AIのために、AIを使った、Effect-TSからの脱却 〜テストを活用した安全なリファクタリングの進め方〜
bitkey
PRO
1
560
基礎から解説!Icebergで紐解くSnowflake×Databricks連携の現在地
cm_yasuhara
0
310
AIが変えた"品質の守り方"
kkakizaki
10
2.8k
Claude Codeですべての日常業務を爆速化しよう!
minorun365
PRO
15
13k
Anthropic AIネイティブ・スタートアップ構築のプレイブック を理解する
nagatsu
0
180
ソフトウェアサプライチェーン攻撃対策として今からサクッとできること
flatt_security
2
140
RubyでRuby拡張を書いたらRubyより35倍速になったってどういうこと??
kazuho
3
610
開発にAIを組織として取り入れる一歩目とその後
yujishibuya
0
220
ルール・ロール・ツールを創る / Creating Rules, Roles and Tools
ks91
PRO
0
160
TypeScriptはどのようにどこまで推論できるのか ─ とにかく as は禁止で
ypresto
3
420
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
200
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.3k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
420
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
180
Six Lessons from altMBA
skipperchong
29
4.2k
The Spectacular Lies of Maps
axbom
PRO
1
760
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
180
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
700
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
200
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.1k
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?