uber

ios-snapshot-test-case

uber

A snapshot testing framework for iOS that validates UI correctness by comparing screenshots of views with reference images.

8.0.0
Published at
Oct 22, 2021
1,865
Stars
71,727
Download
Synced at
Oct 4, 2026

Latest release

8.0.0Oct 22, 2021, 03:40 AM
Downloads slow? Switch the source anytime above

README

Project Overview

iOSSnapshotTestCase (formerly FBSnapshotTestCase) is a snapshot testing framework for iOS. It generates an image snapshot of a configured UIView or CALayer and compares it to a reference image stored in the repository, failing the test if they don't match. This addresses the challenge of testing UI code with traditional logic tests.

Key Features

  • Snapshot Testing: Automatically captures and compares view snapshots.
  • Clear Failure Feedback: Provides image diffs to visually show changes when tests fail.
  • Easy Integration: Supports CocoaPods, Carthage, and Swift Package Manager.
  • Automatic Naming: Automatically names reference images based on test class and selector.

Target Audience

  • iOS developers
  • Teams needing to ensure UI components render correctly under various conditions
  • QA engineers looking to automate UI testing

Quick Start

  1. Add the framework to your project via CocoaPods, Carthage, or Swift Package Manager.
  2. Set the FB_REFERENCE_IMAGE_DIR environment variable in your test scheme to point to the reference image directory.
  3. Create a test class that subclasses FBSnapshotTestCase and call FBSnapshotVerifyView in your test method.
  4. On the first run, enable self.recordMode = YES; in the setUp method to generate reference images.
  5. Disable record mode and run the test again for verification.

Core Advantages

  • Visual Validation: Provides intuitive feedback through image diffs.
  • Reduced Boilerplate: Replaces complex rectangle assertions with visual comparison.
  • Strong Community: Originated from Uber and Facebook, with a solid community base.

System Requirements

  • OS: iOS, macOS (for testing)

Release history

Sort