AN INTRODUCTIONTO SNAPSHOT TESTINGFreek Van der Herten
View Slide
About meFreek Van der HertenDeveloper at SPATIE@freekmurzefreek.devspatie.be/productsohdear.app
spatie.be/open-source300+ open source packagesPHP & Laravel175 million downloads total9 million downloads per month
LET’S TALK ABOUT SNAPSHOT TESTING
What?A file on disk – let’s call it a snapshotTest succeeds if the output matches the snapshotIf not, the test will fail
Where does it come from?Characterisation testingPopularized by FacebookJestTesting interfaces
How can we do it in PHP?github.com/spatie/phpunit-snapshot-assertionsgithub.com/spatie/pest-plugin-snapshotsassertMatchesSnapshotassertMatchesJsonSnapshotassertMatchesXmlSnapshot
DEMO
WRAPPING UP
AdvantagesVery easy to get started withCan be used to validate complex outputEasily update all the tests in one go
DisadvantagesBrittleHard to pinpoint exact point of failureBugs can be easily written in the snapshots
Interesting linksgithub.com/spatie/phpunit-snapshot-assertionsgithub.com/spatie/pest-plugin-snapshotsgithub.com/spatie/shiki-phpgithub.com/spatie/laravel-markdowntorchlight.dev
ONE MORE THING
testing-laravel.comPremium video course, 6+ hours of videoLearn how to tests a Laravel app from scratchTips and tricks to sharpen your skillsTwo courses in one: Pest & PHPUnit10 % discount with SPATIE-LOVES-LARACON
Thank you!spatie.bespatie.be/productsspatie.be/open-sourcetesting-laravel.comfreek.dev