Snapshot Testing in Swift 📸

Roberto Frontado
Devjam
Published in
6 min readSep 29, 2020

--

Illustration from undraw.co

Snapshot tests are an easy way to ensure that the UI doesn’t change unexpectedly when you modify your code. It is a powerful method of testing visual components that works by comparing a snapshot of your UI with a previously-stored reference image, if the two images are the same, the test will pass. If the images are different, the test will fail, and you know something has changed your UI.

Why Snapshot Testing?

Snapshot testing is easy to implement (in most cases). It allows you to keep your UI consistent, meaning there are no more surprises when changing the underlying code.

I can assure you that snapshot testing is much faster than testing the UI manually by launching the app and going through all the screens. The best part? The ability to perform snapshot testing in different devices means your application will look awesome in any resolution.

We will use a framework developed by PointTree called SnapshotTesting, to facilitate the whole process, from taking snapshots of your application to comparing them with the stored snapshots.

--

--