Snapshot Testing

Get to know the pros and cons of snapshot testing.

Introduction

The idea of a snapshot test is to run the code through one or more steps and capture the important output. If we refactor the code and re-run it, does the output change? If so, we’ve likely changed the behavior of the code. We now need to figure out where that was and whether it’s important. If it was unintentional, then we need to correct the code. If the change is insignificant, then we can accept the new output as the “right” output, and use it as the reference against which the next change is tested.

Advantage

The benefit of snapshot testing is that creating snapshots poses little burden. We only need to be able to script our application and filter our output, to grab the important parts.

Disadvantage

The downside of snapshot testing is knowing how to handle a change in output, especially if the developer is being rushed. In general, evaluating code is difficult.

Get hands-on with 1400+ tech skills courses.