Upgrade to Pro — share decks privately, control downloads, hide ads and more …

snapshot testing (laraconus)

snapshot testing (laraconus)

Freek Van der Herten

July 25, 2017
Tweet

More Decks by Freek Van der Herten

Other Decks in Programming

Transcript

  1. A practical intro to
    snapshot testing

    View full-size slide

  2. Pronouncing Dutch
    Michael

    3/10
    Jacob

    1/10

    View full-size slide

  3. Pronouncing Dutch
    Michael

    9/10
    Jacob

    9/10

    View full-size slide

  4. Pronouncing Dutch: Spatie
    Spa Sea

    View full-size slide

  5. LET’S TALK SNAPSHOT TESTING

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  11. 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 full-size slide

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

    View full-size slide