Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
An Introduction to Snapshot testing
Freek Van der Herten
September 01, 2021
Technology
0
250
An Introduction to Snapshot testing
Freek Van der Herten
September 01, 2021
Tweet
Share
More Decks by Freek Van der Herten
See All by Freek Van der Herten
I shall define this only once
freekmurze
0
240
Event Sourcing In Laravel
freekmurze
0
160
Building a realtime dashboard with Laravel Livewire (PHPKonf)
freekmurze
0
520
A tour behind the scenes of Oh Dear (PHP Benelux)
freekmurze
2
540
A practical look at multitenancy in Laravel
freekmurze
1
250
A practical look at multitenancy in Laravel (Laracon US)
freekmurze
0
500
Highlights Flare codebase (Laracon online)
freekmurze
0
220
Introducing Mailcoach
freekmurze
1
420
Highlights from the Flare codebase (Full Stack Ghent)
freekmurze
0
450
Other Decks in Technology
See All in Technology
WINTICKET QA における Autify 活用
kj455
1
190
AI Services 概要 / AI Services overview
oracle4engineer
PRO
0
160
20230123_FinJAWS
takuyay0ne
0
110
【Oracle Cloud ウェビナー】事例から見る規模別クラウド・データベースの選び方 (Oracle Database) (2023年1月18日)
oracle4engineer
PRO
0
100
Virtual Thread - 導入の背景と、効果的な使い方 -
skrb
3
250
立ち止まっても、寄り道しても / even if I stop, even if I take a detour
katoaz
0
140
Periodic Multi-Agent Path Planning
hziwara
0
110
OCIコンテナサービス関連の技術詳細 /oke-ocir-details
oracle4engineer
PRO
0
750
Cloudflare Workersで動くOG画像生成器
aiji42
1
460
Raspberry Pi Camera 3 介紹
piepie_tw
PRO
0
110
400種類のWeb APIをサポートしているデータパイプラインツールにおけるWeb APIとの共存戦略
cdataj
0
140
OVN-Kubernetes-Introduction-ja-2023-01-27.pdf
orimanabu
1
220
Featured
See All Featured
Gamification - CAS2011
davidbonilla
75
4.1k
Build The Right Thing And Hit Your Dates
maggiecrowley
22
1.4k
Designing with Data
zakiwarfel
91
4.2k
The World Runs on Bad Software
bkeepers
PRO
59
5.7k
In The Pink: A Labor of Love
frogandcode
132
21k
GraphQLとの向き合い方2022年版
quramy
20
9.8k
Git: the NoSQL Database
bkeepers
PRO
418
60k
Building an army of robots
kneath
301
40k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
29
7.8k
Fashionably flexible responsive web design (full day workshop)
malarkey
396
63k
A Modern Web Designer's Workflow
chriscoyier
689
180k
Building a Modern Day E-commerce SEO Strategy
aleyda
6
4.5k
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