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
Clean Tests
Search
Noam Almog
February 24, 2017
Programming
87
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Clean Tests
Clean test presentation,
Kiev JUG, 23.2.17
Noam Almog
February 24, 2017
More Decks by Noam Almog
See All by Noam Almog
Rapid Development with Microservices
noamal
0
470
Clean Tests - Scala UA
noamal
0
110
Other Decks in Programming
See All in Programming
継続モナドとリアクティブプログラミング
yukikurage
3
630
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
1
210
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.7k
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
9.3k
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
150
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
150
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
360
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
220
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
140
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
180
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
170
Featured
See All Featured
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
350
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
350
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Making Projects Easy
brettharned
120
6.7k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Ruling the World: When Life Gets Gamed
codingconduct
0
290
Building AI with AI
inesmontani
PRO
1
1.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Evolving SEO for Evolving Search Engines
ryanjones
0
240
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
320
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
190
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]