wireapp/ios-snapshot-test-case

Name: ios-snapshot-test-case

Owner: Wire Swiss GmbH

Description: Snapshot view unit tests for iOS

Forked from: wearezeta/ios-snapshot-test-case

Created: 2016-07-14 14:37:45.0

Updated: 2018-04-10 13:11:27.0

Pushed: 2018-04-10 13:13:15.0

Homepage: null

Size: 849

Language: Objective-C

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

iOSSnapshotTestCase (previously named FBSnapshotTestCase)

Build Status CocoaPods Compatible

What it does

A “snapshot test case” takes a configured UIView or CALayer and uses the renderInContext: method to get an image snapshot of its contents. It compares this snapshot to a “reference image” stored in your source code repository and fails the test if the two images don't match.

Why?

We write a lot of UI code. There are a lot of edge cases that we want to handle correctly when you are creating UIView instances:

It's straightforward to test logic code, but less obvious how you should test views. You can do a lot of rectangle asserts, but these are hard to understand or visualize. Looking at an image diff shows you exactly what changed and how it will look to users.

iOSSnapshotTestCase was developed to make snapshot tests easy.

Installation with CocoaPods
  1. Add the following lines to your Podfile:

    get "Tests" do
    se_frameworks!
    od 'iOSSnapshotTestCase'
    
    

    If your test target is Objective-C only use iOSSnapshotTestCase/Core instead, which doesn't contain Swift support.

    Replace “Tests” with the name of your test project.

  2. There are three ways of setting reference image directories, the recommended one is to define FB_REFERENCE_IMAGE_DIR in your scheme. This should point to the directory where you want reference images to be stored. We normally use this:

|Name|Value| |:—|:—-| |FB_REFERENCE_IMAGE_DIR|$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages| |IMAGE_DIFF_DIR|$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/FailureDiffs|

Define the IMAGE_DIFF_DIR to the directory where you want to store diffs of failed snapshots.

Creating a snapshot test
  1. Subclass FBSnapshotTestCase instead of XCTestCase.
  2. From within your test, use FBSnapshotVerifyView.
  3. Run the test once with self.recordMode = YES; in the test's -setUp method. (This creates the reference images on disk.)
  4. Remove the line enabling record mode and run the test.
Features
Notes

Your unit test must be an “application test”, not a “logic test.” (That is, it must be run within the Simulator so that it has access to UIKit.) In Xcode 5 and later new projects only offer application tests, but older projects will have separate targets for the two types.

Authors

iOSSnapshotTestCase was written at Facebook by Jonathan Dann with significant contributions by Todd Krabach.

Today it is maintained by Uber and Alan Zeino.

License

iOSSnapshotTestCase is MIT?licensed. See LICENSE.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.