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

snapshot testing (phplimburg)

snapshot testing (phplimburg)

Freek Van der Herten

September 07, 2017
Tweet

More Decks by Freek Van der Herten

Other Decks in Programming

Transcript

  1. A practical intro to
    snapshot testing
    and PHPUnit-watcher

    View Slide

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

    View Slide

  3. OPEN SOURCE SOFTWARE

    View Slide

  4. https://spatie.be/en/opensource/laravel

    View Slide

  5. Open source software
    ± 160 public repositories on GitHub
    August 2016: ± 800 000 downloads
    August 2017: ± 5 000 000 downloads
    ± 500 000 downloads a month

    View Slide

  6. LET’S TALK SNAPSHOT TESTING

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  10. DEMO

    View Slide

  11. WRAPPING UP

    View Slide

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

    View Slide

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

    View Slide

  14. 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

    View Slide

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

    View Slide

  16. QUESTIONS?

    View Slide