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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Fran Iglesias
November 02, 2018
Programming
250
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
testing the unpredictable
Non deterministic tests
Fran Iglesias
November 02, 2018
More Decks by Fran Iglesias
See All by Fran Iglesias
Tips for daily refactoring
franiglesias
0
360
Introduction to TDD: Red-Green-Refactor
franiglesias
1
320
Testing value objects
franiglesias
0
280
Tests doubles: the motion picture
franiglesias
0
540
Low cost techniques for test doubles
franiglesias
0
240
Other Decks in Programming
See All in Programming
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
250
net-httpのHTTP/2対応について
naruse
0
490
OSもどきOS
arkw
0
570
Vite+ Unified Toolchain for the Web
naokihaba
0
320
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.6k
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
700
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
140
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
180
Inside Stream API
skrb
1
730
Featured
See All Featured
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
The Limits of Empathy - UXLibs8
cassininazir
1
360
Abbi's Birthday
coloredviolet
2
8.1k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
290
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
250
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
230
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
390
Amusing Abliteration
ianozsvald
1
210
Build your cross-platform service in a week with App Engine
jlugia
234
18k
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