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
320
Introduction to TDD: Red-Green-Refactor
franiglesias
1
250
Testing value objects
franiglesias
0
230
Tests doubles: the motion picture
franiglesias
0
460
Low cost techniques for test doubles
franiglesias
0
180
Other Decks in Programming
See All in Programming
GraphQL×Railsアプリのデータベース負荷分散 - 月間3,000万人利用サービスを無停止で
koxya
1
1.2k
Cloudflare AgentsとAI SDKでAIエージェントを作ってみた
briete
0
140
『毎日の移動』を支えるGoバックエンド内製開発
yutautsugi
2
230
CSC509 Lecture 06
javiergs
PRO
0
260
ポスターセッション: 「まっすぐ行って、右!」って言ってラズパイカーを動かしたい 〜生成AI × Raspberry Pi Pico × Gradioの試作メモ〜
komofr
0
1.2k
All About Angular's New Signal Forms
manfredsteyer
PRO
0
110
CSC509 Lecture 05
javiergs
PRO
0
300
SpecKitでどこまでできる? コストはどれくらい?
leveragestech
0
670
CI_CD「健康診断」のススメ。現場でのボトルネック特定から、健康診断を通じた組織的な改善手法
teamlab
PRO
0
200
明日から始めるリファクタリング
ryounasso
0
130
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
190
コードとあなたと私の距離 / The Distance Between Code, You, and I
hiro_y
0
120
Featured
See All Featured
Building an army of robots
kneath
306
46k
The Art of Programming - Codeland 2020
erikaheidi
56
14k
How to Think Like a Performance Engineer
csswizardry
27
2k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.2k
The Invisible Side of Design
smashingmag
301
51k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
How GitHub (no longer) Works
holman
315
140k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Build your cross-platform service in a week with App Engine
jlugia
232
18k
What's in a price? How to price your products and services
michaelherold
246
12k
RailsConf 2023
tenderlove
30
1.2k
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