Testing UI Automatically with Snapshot Testing 📸✨

Last updated: 9 days ago

One of the main goals when it comes to testing is shipping features with confidence. Manual testing has a high impact on confidence but it's slow and inefficient. Snapshot Testing comes at hand with a fast to write, easy solution for testing UI automatically.

The talk focuses on an open source iOS Framework used to automatically test UI in our iOS codebase. The framework is basically a glorified “pixel-comparison” tool that generates PNG snapshots for all the tested UI and notifies the developer if the UI changed unexpectedly. Snapshot Testing has a high impact on confidence, and it’s the only way we found to test the UI automatically in the iOS codebase.

  • It’s a great way to validate UI easily (3 lines of code for the whole test) in a fast reliable way.
  • Integrating this tool in an existing iOS codebase it’s easy and can be done incrementally.
  • It encourages better isolation in the View layer and in the codebase in general, through dependency injection, in order to avoid flaky snapshot tests.
  • Having a PNG representation of our whole application helps the team understanding how the app looks like without having to build or run any device simulator.
  • PNG snapshots of the app UI can be easily exported and shared between engineers and designers, to make sure that the company's design system is respected as much as possible.