iOS Interview Prep 12 — Snapshot Test
The purpose of this interview preparation series is to assist you in quickly refining your interview skills and thoroughly preparing for the typical questions asked during an iOS interview. If you find it useful, please leave a comment or tap the like button.
Overview
Writing tests for the visual aspects of an app is always challenging. It’s very straightforward to test logical parts but less obvious how to test your UI. This is the reason why so many developers leave their view without testing or investing much effort into UI testing. Apple provides frameworks to help us test logic units, but when it comes to testing the end result of what the user actually sees there’s not much support. Snapshot tests help us solve these issues, it’s easy to set up and write view-based tests.
Why Snapshot Test?
iOS developers write lots of UI code, if you want to test the UI through code it’s almost impossible due to the number of states and corner cases even for a simple UI. Snapshot testing is easy to integrate into your project, it allows us to verify the high-level appearance of views. Each snapshot is compared to the previous version to prevent visual regressions.
The normal workflow to test your UI changes
- Build the app