talira

SnapshotTesting

Snapshot testing for Swift: assert on images, text, JSON or any value against recorded references

open sourceMITfree

SnapshotTesting (swift-snapshot-testing) from Point-Free lets Swift tests call assertSnapshot on any value with a snapshot strategy: views and view controllers as images, data structures as text, JSON or property lists, and anything you can turn into an image, string or diffable data. The first run records a reference to disk next to the tests; later runs compare against it and describe any difference, with image diffs attached in Xcode and text diffs inline. It needs no configuration, works from XCTest or Swift Testing, renders views for specific devices from a single simulator, and runs on iOS, macOS, tvOS and Linux.

Problems it solves

  • catch unintended UI changes in my iOS views with snapshot tests
  • compare my Swift view's rendering against a recorded reference image
  • snapshot test the JSON my Swift code encodes

Features

  • dozens of snapshot strategies for images, text, JSON and property lists
  • write your own snapshot strategies or transform existing ones
  • snapshots recorded automatically next to the tests, with no configuration
  • device-agnostic view snapshots from a single simulator
  • image diffs as XCTest attachments and text diffs inline in Xcode
  • SceneKit, SpriteKit and WebKit view support
  • print diff commands for Kaleidoscope or another diff tool

Alternatives

The same job

These do what SnapshotTesting does.

  1. Chromatic Ship flawless UIs with less work
  2. Sauce Labs Verify AI-generated code at the pace it's written
  3. Percy AI-powered visual testing and review

Compare SnapshotTesting with the top 3