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
200
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
330
Introduction to TDD: Red-Green-Refactor
franiglesias
1
260
Testing value objects
franiglesias
0
240
Tests doubles: the motion picture
franiglesias
0
470
Low cost techniques for test doubles
franiglesias
0
190
Other Decks in Programming
See All in Programming
CSC305 Lecture 11
javiergs
PRO
0
320
Introduce Hono CLI
yusukebe
6
3.3k
なんでRustの環境構築してないのにRust製のツールが動くの? / Why Do Rust-Based Tools Run Without a Rust Environment?
ssssota
14
47k
品質ワークショップをやってみた
nealle
0
810
Inside of Swift Export
giginet
PRO
1
260
CSC509 Lecture 08
javiergs
PRO
0
270
Go言語はstack overflowの夢を見るか?
logica0419
0
670
AIと人間の共創開発!OSSで試行錯誤した開発スタイル
mae616
2
850
SODA - FACT BOOK(JP)
sodainc
1
9.1k
CSC305 Lecture 12
javiergs
PRO
0
250
Researchlyの開発で参考にしたデザイン
adsholoko
0
100
Webサーバーサイド言語としてのRustについて
kouyuume
1
5k
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.3k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
253
22k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Context Engineering - Making Every Token Count
addyosmani
8
330
GraphQLとの向き合い方2022年版
quramy
49
14k
A better future with KSS
kneath
239
18k
Product Roadmaps are Hard
iamctodd
PRO
55
11k
The Cost Of JavaScript in 2023
addyosmani
55
9.1k
Balancing Empowerment & Direction
lara
5
710
Writing Fast Ruby
sferik
630
62k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
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