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
150
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
290
Introduction to TDD: Red-Green-Refactor
franiglesias
1
170
Testing value objects
franiglesias
0
160
Tests doubles: the motion picture
franiglesias
0
330
Low cost techniques for test doubles
franiglesias
0
120
Other Decks in Programming
See All in Programming
What We Can Learn From OSS
inouehi
0
420
Rethinking UI building strategies @ SFI 2024
letelete
0
270
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
Fragment Composition of GraphQL
quramy
4
750
ONE WEDGE_company_guide
1wedge_one
0
470
MicrosoftのPlatform Engineeringガイドを読んで実際になにかやってみた
ymd65536
1
300
デフォルトにして至高、RubyMineの大好きな所
ruzia
0
290
Goのエラースタックトレースの歴史と今後
sonatard
7
1.2k
dbtのドメイン分割による データ基盤の改善とDigdagとの連携
sakama
0
100
AWS Application Composerで始める、 サーバーレスなデータ基盤構築 / 20240406-jawsug-hokuriku-shinkansen
kasacchiful
1
260
TYPO3 v13 – The road to LTS: What's new and new APIs
luisasofie_xoxo
0
200
冗長なエラーログを削減し、スタックトレースを手に入れる / Reducing Verbose Error Logs and Obtaining Stack Traces
upamune
0
480
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
225
17k
Design by the Numbers
sachag
274
18k
GitHub's CSS Performance
jonrohan
1025
450k
VelocityConf: Rendering Performance Case Studies
addyosmani
320
23k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Fireside Chat
paigeccino
21
2.6k
The Language of Interfaces
destraynor
151
23k
How To Stay Up To Date on Web Technology
chriscoyier
782
250k
Why You Should Never Use an ORM
jnunemaker
PRO
51
8.6k
Gamification - CAS2011
davidbonilla
76
4.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
121
39k
Six Lessons from altMBA
skipperchong
21
3k
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