Name: ios-snapshot-test-case
Owner: AutoScout24
Owner: AutoScout24
Description: Snapshot view unit tests for iOS
Created: 2013-11-04 13:03:07.0
Updated: 2015-01-26 15:32:50.0
Pushed: 2016-08-04 15:49:48.0
Homepage: null
Size: 645
Language: Objective-C
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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.
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.
We developed FBSnapshotTestCase
to make snapshot tests easy.
Add the following lines to your Podfile:
get "Tests" do
od 'FBSnapshotTestCase'
If you support iOS 7 use FBSnapshotTestCase/Core
instead, which doesn't contain Swift support.
Replace “Tests” with the name of your test project.
Define FB_REFERENCE_IMAGE_DIR
in your scheme. This should
point to the directory where you want reference images to be stored. At Facebook,
we normally use this:
|Name|Value|
|:—|:—-|
|FB_REFERENCE_IMAGE_DIR
|$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages
|
FBSnapshotTestCase
instead of XCTestCase
.FBSnapshotVerifyView
.self.recordMode = YES;
in the test's -setUp
method. (This creates the reference images on disk.)CALayer
via FBSnapshotVerifyLayer
.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
was written at Facebook by
Jonathan Dann with significant contributions by
Todd Krabach.
FBSnapshotTestCase
is BSD-licensed. See LICENSE
.
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.
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.
We developed FBSnapshotTestCase
to make snapshot tests easy.
Add the following lines to your Podfile:
get "Tests" do
od 'FBSnapshotTestCase'
If you support iOS 7 use FBSnapshotTestCase/Core
instead, which doesn't contain Swift support.
Replace “Tests” with the name of your test project.
Define FB_REFERENCE_IMAGE_DIR
in your scheme. This should
point to the directory where you want reference images to be stored. At Facebook,
we normally use this:
|Name|Value|
|:—|:—-|
|FB_REFERENCE_IMAGE_DIR
|$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages
|
FBSnapshotTestCase
instead of XCTestCase
.FBSnapshotVerifyView
.self.recordMode = YES;
in the test's -setUp
method. (This creates the reference images on disk.)CALayer
via FBSnapshotVerifyLayer
.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
was written at Facebook by
Jonathan Dann with significant contributions by
Todd Krabach.
FBSnapshotTestCase
is BSD-licensed. See LICENSE
.