Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Clean Tests
Search
Noam Almog
February 24, 2017
Programming
0
75
Clean Tests
Clean test presentation,
Kiev JUG, 23.2.17
Noam Almog
February 24, 2017
Tweet
Share
More Decks by Noam Almog
See All by Noam Almog
Rapid Development with Microservices
noamal
0
440
Clean Tests - Scala UA
noamal
0
110
Other Decks in Programming
See All in Programming
認証・認可の基本を学ぼう後編
kouyuume
0
240
Socio-Technical Evolution: Growing an Architecture and Its Organization for Fast Flow
cer
PRO
0
340
テストやOSS開発に役立つSetup PHP Action
matsuo_atsushi
0
160
ハイパーメディア駆動アプリケーションとIslandアーキテクチャ: htmxによるWebアプリケーション開発と動的UIの局所的適用
nowaki28
0
420
AIコーディングエージェント(Gemini)
kondai24
0
230
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
38
26k
複数人でのCLI/Infrastructure as Codeの暮らしを良くする
shmokmt
5
2.3k
配送計画の均等化機能を提供する取り組みについて(⽩⾦鉱業 Meetup Vol.21@六本⽊(数理最適化編))
izu_nori
0
150
認証・認可の基本を学ぼう前編
kouyuume
0
250
Github Copilotのチャット履歴ビューワーを作りました~WPF、dotnet10もあるよ~ #clrh111
katsuyuzu
0
110
ViewファーストなRailsアプリ開発のたのしさ
sugiwe
0
470
リリース時」テストから「デイリー実行」へ!開発マネージャが取り組んだ、レガシー自動テストのモダン化戦略
goataka
0
130
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
It's Worth the Effort
3n
187
29k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.6k
Site-Speed That Sticks
csswizardry
13
1k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.3k
Designing for humans not robots
tammielis
254
26k
How to train your dragon (web standard)
notwaldorf
97
6.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1k
Transcript
Clean Tests Noam Almog | Tech Lead linkedin github.com/noam-almog @NoamSon
[email protected]
Hi. Tech Lead Wix.com Noam Almog
AGENDA Intro Review Test Structures Refactor each part of the
test Conclude
Should I Clean ? § Test lasts More than production
Code. § More Lines of code § Read and reviewed More
If you let the tests rot, then your code will
rot too “ “ Robert C. Martin
What Is ”Good” ? § How easy is it to
extend it ? § When break, is it easy to fix ? § How many “Rewrite” calls ?
Test Structure 01
Test Structure § Test is a Map to your code.
§ Reveille the right amount of details. § Should be Consistent (*)
Test Structure
From Testing Code to Testing Behavior
Structure Pitfalls Test only one thing
Structure Pitfalls Hide Too Much Data
Send Mail invoke
New Test 01
Test Description § Use Plain English § Use Simple Language
– Not Code ! § Find a sentence structure § “throw an exception if user does not exist” § “send an email to the the email registered with the site-id”
Test Description Does not Compile
Test Setup 02
Can A Single Test Case Stand on His own
Extract Setup to Methods § Select method name that implies
structure § Starts with given § Contain the collaborator name § Describe the defined Behavior § Reverse the order of parameters § Use parameter names to show what is important
Describe the What are testing, NOT How you are testing
Simplify The Code § Do not use concrete values in
the test. § Reduce number of moving parts § Do not move important logic out of the scope
Extract Drivers § Move all setup method to it §
Move all related variables to it § Split according to the Subject
When is a good time to start ? Now !
Test Action 03
Test Action § Should be a single statement § Do
NOT hide !
Test Expectations 04
Matchers, Why ? § Readable § Better Failure Messages §
Reusable and Flexible
Matcher libraries § Hamcrest (Java) § Chai (JS) § Specs2/ScalaTest
(Scala)
Match Expectations § Use just one matcher § Describe what
you are matching, now how § Don’t define any new variables
Use Only what You Defined
Failure Messages Can you tell me why this failed ?
Conclusion § Test behavior and not code § Test Should
stand on his own § Describe what and not how § Start today, don’t wait for tomorrow § Use only variables you defined
Thank You linkedin github.com/noam-almog @NoamSon
[email protected]
Q&A linkedin github.com/noam-almog @NoamSon
[email protected]