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
An Introduction to Snapshot testing
Search
Freek Van der Herten
September 01, 2021
Technology
560
0
Share
An Introduction to Snapshot testing
Freek Van der Herten
September 01, 2021
More Decks by Freek Van der Herten
See All by Freek Van der Herten
Uncharted packages (ode aan de code)
freekmurze
0
62
Uncharted packages (Laravel Live Denmark)
freekmurze
0
250
I shall define this only once
freekmurze
0
480
Event Sourcing In Laravel
freekmurze
0
280
Building a realtime dashboard with Laravel Livewire (PHPKonf)
freekmurze
0
860
A tour behind the scenes of Oh Dear (PHP Benelux)
freekmurze
2
910
A practical look at multitenancy in Laravel
freekmurze
1
400
A practical look at multitenancy in Laravel (Laracon US)
freekmurze
0
780
Highlights Flare codebase (Laracon online)
freekmurze
0
580
Other Decks in Technology
See All in Technology
コードや知識を組み込む / Incorporate Code and Knowledge
ks91
PRO
0
170
Rapid Start: Faster Internet Connections, with Ruby's Help
kazuho
2
770
[OpsJAWS 40]リリースしたら終わり、じゃなかった。セキュリティ空白期間をAWS Security Agentで埋める
sh_fk2
3
250
ネットワーク運用を楽にするAWS DevOps Agent活用法!! / 20260421 Masaki Okuda
shift_evolve
PRO
2
230
Route 53 Global Resolver で高額課金発生!
otanikohei2023
0
120
運用システムにおけるデータ活用とPlatform
sansantech
PRO
0
120
Claude Code を安全に使おう勉強会 / Claude Code Security Basics
masahirokawahara
12
37k
これからの「データマネジメント」の話をしよう
sansantech
PRO
0
150
エージェントスキルを作って自分のインプットに役立てよう
tsubakimoto_s
0
440
Practical TypeProf: Lessons from Analyzing Optcarrot
mame
0
1.1k
音声言語モデル手法に関する発表の紹介
kzinmr
0
130
Do Ruby::Box dream of Modular Monolith?
joker1007
1
350
Featured
See All Featured
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
110
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.4k
New Earth Scene 8
popppiees
3
2.1k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
380
Heart Work Chapter 1 - Part 1
lfama
PRO
6
35k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
140
Between Models and Reality
mayunak
3
270
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Scaling GitHub
holman
464
140k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
320
The SEO identity crisis: Don't let AI make you average
varn
0
450
GitHub's CSS Performance
jonrohan
1032
470k
Transcript
AN INTRODUCTION TO SNAPSHOT TESTING Freek Van der Herten
About me Freek Van der Herten Developer at SPATIE @freekmurze
freek.dev spatie.be/products ohdear.app
spatie.be/open-source 300+ open source packages PHP & Laravel 175 million
downloads total 9 million downloads per month
LET’S TALK ABOUT SNAPSHOT TESTING
What? A file on disk – let’s call it a
snapshot Test succeeds if the output matches the snapshot If not, the test will fail
Where does it come from? Characterisation testing Popularized by Facebook
Jest Testing interfaces
How can we do it in PHP? github.com/spatie/phpunit-snapshot-assertions github.com/spatie/pest-plugin-snapshots assertMatchesSnapshot
assertMatchesJsonSnapshot assertMatchesXmlSnapshot
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
Interesting links github.com/spatie/phpunit-snapshot-assertions github.com/spatie/pest-plugin-snapshots github.com/spatie/shiki-php github.com/spatie/laravel-markdown torchlight.dev
ONE MORE THING
testing-laravel.com Premium video course, 6+ hours of video Learn how
to tests a Laravel app from scratch Tips and tricks to sharpen your skills Two courses in one: Pest & PHPUnit 10 % discount with SPATIE-LOVES-LARACON
Thank you! spatie.be spatie.be/products spatie.be/open-source testing-laravel.com freek.dev