|ReleasedLast Release||Oct 2016|
|Apps WeekApps This Week||4|
|Pod Tries WeekPod Tries This Week||6|
|Test WeekTests This week||449|
|LOCLines of Code||887|
A "snapshot test case" takes a configured
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.
At Facebook we write a lot of UI code. As you might imagine, each type of
feed story is rendered using a subclass of
UIView. There are a lot of edge
cases that we want to handle correctly:
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.
FBSnapshotTestCase to make snapshot tests easy.
self.recordMode = YES;in the test's
-setUpmethod. (This creates the reference images on disk.)
usesDrawViewHierarchyInRectto handle cases like
UIAppearanceand Size Classes.
isDeviceAgnosticto allow appending the device model (
iPod Touch, etc), OS version and screen size to the images (allowing to have multiple tests for the same «snapshot» for different
OSs and devices).
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.
FBSnapshotTestCase is BSD-licensed. See