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
170
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
200
Tests doubles: the motion picture
franiglesias
0
420
Low cost techniques for test doubles
franiglesias
0
150
Other Decks in Programming
See All in Programming
ABEMA iOS 大規模プロジェクトにおける段階的な技術刷新 / ABEMA iOS Technology Upgrade
akkyie
1
260
技術を改善し続ける
gumioji
0
180
From the Wild into the Clouds - Laravel Meetup Talk
neverything
0
190
複数のAWSアカウントから横断で 利用する Lambda Authorizer の作り方
tc3jp
0
130
Webフレームワークとともに利用するWeb components / JSConf.jp おかわり
spring_raining
1
150
Expoによるアプリ開発の現在地とReact Server Componentsが切り開く未来
yukukotani
2
290
Amazon Bedrockマルチエージェントコラボレーションを諦めてLangGraphに入門してみた
akihisaikeda
1
180
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
0
100
ML.NETで始める機械学習
ymd65536
0
250
Devin入門 〜月500ドルから始まるAIチームメイトとの開発生活〜 / Introduction Devin 〜Development With AI Teammates〜
rkaga
3
1.3k
CDKを使ったPagerDuty連携インフラのテンプレート化
shibuya_shogo
0
130
楽しく向き合う例外対応
okutsu
0
760
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
11
1.3k
Practical Orchestrator
shlominoach
186
10k
We Have a Design System, Now What?
morganepeng
51
7.4k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
11
550
Java REST API Framework Comparison - PWX 2021
mraible
29
8.4k
RailsConf 2023
tenderlove
29
1k
Build The Right Thing And Hit Your Dates
maggiecrowley
34
2.5k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.4k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Speed Design
sergeychernyshev
28
820
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