Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
snapshot testing (phplimburg)
Freek Van der Herten
September 07, 2017
Programming
1
74
snapshot testing (phplimburg)
Freek Van der Herten
September 07, 2017
Tweet
Share
More Decks by Freek Van der Herten
See All by Freek Van der Herten
freekmurze
0
68
freekmurze
0
250
freekmurze
1
370
freekmurze
1
190
freekmurze
0
350
freekmurze
0
110
freekmurze
1
320
freekmurze
0
320
freekmurze
0
100
Other Decks in Programming
See All in Programming
mfunaki
1
770
mitohato14
0
110
sters
2
120
hackz_inc
0
310
osyo
0
280
ryokbt
2
280
zwass
0
350
danilop
1
730
danilop
0
220
ntaro
0
160
christianliebel
PRO
0
130
larsrh
0
110
Featured
See All Featured
kneath
219
15k
shpigford
369
42k
destraynor
223
47k
deanohume
295
28k
holman
448
130k
jacobian
255
20k
colly
66
3k
danielanewman
200
20k
chriscoyier
684
180k
mongodb
23
3.9k
lauravandoore
11
1.5k
akmur
252
19k
Transcript
A practical intro to snapshot testing and PHPUnit-watcher
About me Freek Van der Herten Partner & developer at
SPATIE Blogging at https://murze.be https://murze.be/newsletter
OPEN SOURCE SOFTWARE
https://spatie.be/en/opensource/laravel
Open source software ± 160 public repositories on GitHub August
2016: ± 800 000 downloads August 2017: ± 5 000 000 downloads ± 500 000 downloads a month
LET’S TALK SNAPSHOT TESTING
A file on disk, let’s call in snapshot Test succeeds
if output matches snapshot If not, test will fail What?
Another name: characterization testing Popularized by Facebook Jest Testing interfaces
Where does it come from?
https://github.com/spatie/phpunit-snapshot-assertions assertMatchesSnapshot assertMatchesJsonSnapshot assertMatchesXmlSnapshot How can we do it in
PHP?
DEMO
WRAPPING UP
Advantages Very easy to get started with Can be used
to validate complex output Easily update all the tests in one go
Disadvantages Brittle Hard to pinpoint exact point of failure Bugs
can be easily written in the snapshots
https://github.com/spatie/phpunit-snapshot-assertions https://sebastiandedeyne.com/posts/2017/a-package-for-snapshot- testing-in-phpunit https://murze.be/2017/04/practical-introduction-snapshot-testing/ https://www.sitepoint.com/snapshot-testing-viable-php/ https://facebook.github.io/jest/docs/snapshot-testing.html https://github.com/spatie/phpunit-watcher Interesting links
Thank you! https://speakerdeck.com/freekmurze/snapshot-testing-phplimburg https://spatie.be/opensource https://murze.be https://murze.be/newsletter/
QUESTIONS?