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
250
0
Share
testing the unpredictable
Non deterministic tests
Fran Iglesias
November 02, 2018
More Decks by Fran Iglesias
See All by Fran Iglesias
Tips for daily refactoring
franiglesias
0
360
Introduction to TDD: Red-Green-Refactor
franiglesias
1
310
Testing value objects
franiglesias
0
280
Tests doubles: the motion picture
franiglesias
0
530
Low cost techniques for test doubles
franiglesias
0
230
Other Decks in Programming
See All in Programming
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
440
Modding RubyKaigi for Myself
yui_knk
0
760
次世代リンターで探る、tsgo 時代における型認識カスタムルールの現実解
ytakahashii
3
1.3k
TypeSpec で繋ぐ複数プロダクトの型安全
maroon8021
1
260
Hive Metastoreを通して学ぶIceberg REST Catalog ― 仕様から実装まで
okumin
0
300
新規プロダクトを高速で生み出すハーネスエンジニアリング
seanchas116
15
7.3k
[BalkanRuby 2026] Drop your app/services!
palkan
3
720
AI駆動開発勉強会 広島支部 第一回勉強会 AI駆動開発概要とワークショップ
hayatoshimiu
0
410
権限チェックの一貫性を型で守る TypeScript による多層防御
mnch
4
940
Inspired By RubyKaigi (EN)
atzzcokek
0
390
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3k
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.2k
Featured
See All Featured
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.3k
Rails Girls Zürich Keynote
gr2m
96
14k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.1k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
200
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
820
The untapped power of vector embeddings
frankvandijk
2
1.7k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
560
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
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