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.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
TypeScript で Platform SDK を作る技術
toiroakr
1
300
RubyでRuby拡張を書いたらRubyより35倍速になったってどういうこと??
kazuho
3
610
はじめてのAI-DLC
yoshidashingo
2
530
checker.tsにチキンレースを仕掛けてみた:型エラー(TS2589)が発生する境界線を求めて
hal_spidernight
1
200
20260528_生成AIを専属DSに_Howの次にすべきことを考える
doradora09
PRO
0
200
LLM時代のリファクタリング戦略_AIエージェントによる段階的・安全なTS移行方法
play_inc
0
180
Agentic AI時代における メルカリのAIガバナンスとガードレール実装
naoichihara
15
14k
Splunk MCPサーバの利活用事例 ーKINTOテクノロジーズの取り組み
kintotechdev
1
320
コーディングエージェントはTypeScriptの 型エラーをどう自己修正しているのか
melonps
4
480
イベントストーミングとKiroの仕様駆動開発で実現する要件の認識合わせプロセス
syobochim
5
420
Harnessing the Power of Mocks and Stubs in PHPUnit / #laravellivejp
asumikam
0
560
NFLコンペ2026 解法
lycorptech_jp
PRO
0
110
Featured
See All Featured
Code Review Best Practice
trishagee
74
20k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
560
The agentic SEO stack - context over prompts
schlessera
0
780
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
WENDY [Excerpt]
tessaabrams
10
37k
Git: the NoSQL Database
bkeepers
PRO
432
67k
The Limits of Empathy - UXLibs8
cassininazir
1
340
Believing is Seeing
oripsolob
1
130
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
790
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
190
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.7k
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?