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
160
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
310
Introduction to TDD: Red-Green-Refactor
franiglesias
1
210
Testing value objects
franiglesias
0
190
Tests doubles: the motion picture
franiglesias
0
410
Low cost techniques for test doubles
franiglesias
0
140
Other Decks in Programming
See All in Programming
自分ひとりから始められる生産性向上の取り組み #でぃーぷらすオオサカ
irof
8
2k
Azure AI Foundryのご紹介
qt_luigi
1
240
[JAWS-UG横浜 #80] うわっ…今年のServerless アップデート、少なすぎ…?
maroon1st
0
130
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
800
2024年のkintone API振り返りと2025年 / kintone API look back in 2024
tasshi
0
160
Package Traits
ikesyo
2
220
2025.01.17_Sansan × DMM.swift
riofujimon
2
630
Fixstars高速化コンテスト2024準優勝解法
eijirou
0
190
Scaling your build logic
antalmonori
1
130
Beyond ORM
77web
11
1.6k
Amazon Nova Reelの可能性
hideg
0
240
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.2k
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
Documentation Writing (for coders)
carmenintech
67
4.6k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
980
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Speed Design
sergeychernyshev
25
750
How GitHub (no longer) Works
holman
312
140k
GraphQLとの向き合い方2022年版
quramy
44
13k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
360
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