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
testing the unpredictable
Search
Fran Iglesias
November 02, 2018
Programming
0
190
testing the unpredictable
Non deterministic tests
Fran Iglesias
November 02, 2018
Tweet
Share
More Decks by Fran Iglesias
See All by Fran Iglesias
Tips for daily refactoring
franiglesias
0
320
Introduction to TDD: Red-Green-Refactor
franiglesias
1
240
Testing value objects
franiglesias
0
220
Tests doubles: the motion picture
franiglesias
0
450
Low cost techniques for test doubles
franiglesias
0
170
Other Decks in Programming
See All in Programming
Improving my own Ruby thereafter
sisshiki1969
1
110
Understanding Ruby Grammar Through Conflicts
yui_knk
1
140
ECS初心者の仲間 – TUIツール「e1s」の紹介
keidarcy
0
110
SOCI Index Manifest v2が出たので調べてみた / Introduction to SOCI Index Manifest v2
tkikuc
1
110
マイコンでもRustのtestがしたい その2/KernelVM Tokyo 18
tnishinaga
2
2.3k
オープンセミナー2025@広島LT技術ブログを続けるには
satoshi256kbyte
0
140
Claude Codeで実装以外の開発フロー、どこまで自動化できるか?失敗と成功
ndadayo
2
1.7k
STUNMESH-go: Wireguard NAT穿隧工具的源起與介紹
tjjh89017
0
390
ワープロって実は計算機で
pepepper
2
1.4k
自作OSでDOOMを動かしてみた
zakki0925224
1
1.4k
Trem on Rails - Prompt Engineering com Ruby
elainenaomi
1
100
Ruby Parser progress report 2025
yui_knk
1
170
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
236
140k
BBQ
matthewcrist
89
9.8k
Music & Morning Musume
bryan
46
6.8k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Into the Great Unknown - MozCon
thekraken
40
2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Automating Front-end Workflow
addyosmani
1370
200k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
[RailsConf 2023] Rails as a piece of cake
palkan
56
5.8k
The Art of Programming - Codeland 2020
erikaheidi
55
13k
A designer walks into a library…
pauljervisheath
207
24k
Transcript
TDD 101 4. Testing the unpredictable
Testing the unpredictable
Testing the unpredictable Elements beyond our system: • Randomness •
Time • File system You can’t rely on their behavior
How can we test?
1. Things that are using unpredictable components They are global
state dependencies Isolate and extract Invert dependency Stub for testing
Example class User { private $id; private $name; public function
__construct(string $name) { $this->id = Uuid::uuid4(); $this->name = $name; } }
Example class User { private $id; private $name; public function
__construct( UserId $id, string $name ) { $this->id = $id; $this->name = $name; } }
2. Things that are unpredictable Don’t test what you don’t
own Test for properties of the output, not the output itself
Example class PasswordGeneratorTest extends TestCase { public function testShouldBeLongEnough() {
$password = $this->generator->generate(); $this->assertTrue(strlen($password) > 9); } }
Avoid coupling with dependency inversion
Dependency Inversion High level modules should not depend on low
level modules, both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions.
Thigh coupling MyClass Dependency Uses
Dependency inversion MyClass Interface Dependency Uses Implements
Dependency inversion & adapter pattern MyClass Interface Dependency Uses Implements
Adapter Uses
None