$30 off During Our Annual Pro Sale. View Details »

Snapshot testing (nomadphp)

Snapshot testing (nomadphp)

Freek Van der Herten

July 20, 2017
Tweet

More Decks by Freek Van der Herten

Other Decks in Technology

Transcript

  1. A practical intro to
    snapshot testing

    View Slide

  2. About me
    Freek Van der Herten
    Partner & developer at SPATIE
    @freekmurze
    https://murze.be

    View Slide

  3. About me
    phpantwerp.be
    Dries Vints
    @driesvints
    Frederick Vanbrabant
    @TheEdonian

    View Slide

  4. Since 2003
    Websites, applications and webshops
    Team
    4 developers, 1 manager
    Specialization
    Laravel development

    View Slide

  5. OPEN SOURCE SOFTWARE

    View Slide

  6. ± 120 packages on Packagist
    Laravel, Framework agnostic PHP
    ± 4 000 000 downloads in total, growing ±500 000 a month
    We create a lot of it
    Open source software

    View Slide

  7. http://github-awards.com/users?type=world&language=php
    Open source software

    View Slide

  8. LET’S TALK SNAPSHOT TESTING

    View Slide

  9. A file on disk, let’s call in snapshot
    Test succeeds if output matches snapshot
    If not, test will fail
    What?

    View Slide

  10. Old name: characterization testing
    Popularized by Facebook
    Jest
    Testing interfaces
    Where does it come from?

    View Slide

  11. https://github.com/spatie/phpunit-snapshot-assertions
    assertMatchesSnapshot
    assertMatchesJsonSnapshot
    assertMatchesXmlSnapshot
    How can we do it in PHP?

    View Slide

  12. DEMO

    View Slide

  13. WRAPPING UP

    View Slide

  14. Advantages
    Very easy to get started with
    Can be used to validate complex output
    Easily update all the tests in one go

    View Slide

  15. Disadvantages
    Brittle
    Hard to pinpoint exact point of failure
    Bugs can be easily written in the snapshots

    View Slide

  16. 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
    Interesting links

    View Slide

  17. Thank you!
    https://speakerdeck.com/freekmurze/snapshot-testing-nomadphp
    https://spatie.be/opensource
    https://murze.be
    https://murze.be/newsletter/

    View Slide

  18. QUESTIONS?

    View Slide