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
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
450
Clean Tests - Scala UA
noamal
0
110
Other Decks in Programming
See All in Programming
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
130
Patterns of Patterns
denyspoltorak
0
1.4k
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
CSC307 Lecture 08
javiergs
PRO
0
670
Fluid Templating in TYPO3 14
s2b
0
130
「ブロックテーマでは再現できない」は本当か?
inc2734
0
100
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
250
Fragmented Architectures
denyspoltorak
0
150
Basic Architectures
denyspoltorak
0
660
Grafana:建立系統全知視角的捷徑
blueswen
0
320
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
940
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
RailsConf 2023
tenderlove
30
1.3k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
320
Designing for humans not robots
tammielis
254
26k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Evolving SEO for Evolving Search Engines
ryanjones
0
120
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
50
GitHub's CSS Performance
jonrohan
1032
470k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
110
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
170
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
62
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
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]