All Projects → parski → Snapshottest

parski / Snapshottest

Licence: bsd-2-clause
Snapshot testing tool for iOS and tvOS

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Snapshottest

carina-demo
Carina demo project.
Stars: ✭ 40 (-4.76%)
Mutual labels:  tvos, testing-tools
Fontblaster
Programmatically load custom fonts into your iOS and tvOS app.
Stars: ✭ 1,000 (+2280.95%)
Mutual labels:  tvos
Cypress
Fast, easy and reliable testing for anything that runs in a browser.
Stars: ✭ 35,145 (+83578.57%)
Mutual labels:  testing-tools
Sica
🦌 Simple Interface Core Animation. Run type-safe animation sequencially or parallelly
Stars: ✭ 980 (+2233.33%)
Mutual labels:  tvos
Queuer
Queuer is a queue manager, built on top of OperationQueue and Dispatch (aka GCD).
Stars: ✭ 964 (+2195.24%)
Mutual labels:  tvos
Webmockr
R library for stubbing and setting expectations on HTTP requests
Stars: ✭ 37 (-11.9%)
Mutual labels:  testing-tools
Life
Conway's Game of Life written in Swift 👾
Stars: ✭ 21 (-50%)
Mutual labels:  tvos
Fugen
Command line tool for exporting resources and generating code from your Figma files
Stars: ✭ 41 (-2.38%)
Mutual labels:  tvos
Junit Extensions
JUnit5 extensions library including JUnit5 equivalents of some of the common JUnit4 rules: ExpectedException, TemporaryFolder etc
Stars: ✭ 39 (-7.14%)
Mutual labels:  testing-tools
Rxschedulerrule
Simple JUnit rule for overriding RxJava/RxAndroid schedulers during unit tests
Stars: ✭ 35 (-16.67%)
Mutual labels:  testing-tools
Mts
Project of Multi-protocol Test Tool opensourced by Ericsson
Stars: ✭ 34 (-19.05%)
Mutual labels:  testing-tools
Centeredcollectionview
A lightweight UICollectionViewLayout that 'pages' and centers its cells 🎡 written in Swift
Stars: ✭ 965 (+2197.62%)
Mutual labels:  tvos
Sqlitelib
Easily build a custom SQLite static library for use in macOS and iOS frameworks and apps.
Stars: ✭ 38 (-9.52%)
Mutual labels:  tvos
Xcconfigs
Collection of common Xcode configuration files. 🛠
Stars: ✭ 28 (-33.33%)
Mutual labels:  tvos
Websocket Connection Smuggler
websocket-connection-smuggler
Stars: ✭ 40 (-4.76%)
Mutual labels:  testing-tools
Hoppscotch
👽 Open source API development ecosystem https://hoppscotch.io
Stars: ✭ 34,569 (+82207.14%)
Mutual labels:  testing-tools
Pyats Docker
Dockerfile and scripts for pyATS
Stars: ✭ 34 (-19.05%)
Mutual labels:  testing-tools
Oauth2
OAuth2 framework for macOS and iOS, written in Swift.
Stars: ✭ 983 (+2240.48%)
Mutual labels:  tvos
Detox
High velocity native mobile development requires us to adopt continuous integration workflows, which means our reliance on manual QA has to drop significantly. Detox tests your mobile app while it’s running in a real device/simulator, interacting with it just like a real user.
Stars: ✭ 8,988 (+21300%)
Mutual labels:  testing-tools
Pyspecs
Minimalistic BDD in Python
Stars: ✭ 40 (-4.76%)
Mutual labels:  testing-tools

master

SnapshotTest is a simple view testing tool written completely in Swift to aid with development for Apple platforms. It's like unit testing for views.

How

When record mode is active a snapshot assertion will record an image of the view and save it to a specified directory. This will cause the test to fail. When record mode is deactivated the snapshot assertion will record an image of the view and compare it to the saved reference image. Should they differ the test will fail.

Setup

All SnapshotTest needs to know is where to save the reference images. This directory is specified using a test scheme environmental variable using the key:

REFERENCE_IMAGE_DIR

Recommended reference image directory path is:

$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages

It should look something like this:

Test scheme arguments.

Usage

If you are familiar with XCTest using SnapshotTest will be a breeze. Instead of subclassing XCTestCase you just need to subclass SnapshotTestCase and assert the view using AssertSnapshot() to test it.

class ViewTests: SnapshotTestCase {
    
    func testView_withAlteration() {
        // Given
        let view = View(frame: CGRect(x: 0, y: 0, width: 375, height: 100))
        
        // When
        view.alter()
        
        // Then
        AssertSnapshot(view)
    }
    
}

Currently UIView, UIViewController and CALayer are supported.

Record mode

Record mode records a snapshot of your view within the current scope and stores it in the reference directory to compare with any subsequent assertions.

Note that record mode will fail the test and output the reference image path to the console.

🔴 RECORD MODE: Reference image saved to /Users/snap/App/AppTests/ReferenceImages/View/testView_withAlteration.png

Test case

To set the test case to record mode simply change the recordMode property to true.

class ViewTests: SnapshotTestCase {
    
    override func setUp() {
        super.setUp()
        recordMode = true
    }
    
}

The assertion will then record and save a reference image.

Global

To set record mode globally and record all snapshots for every assertion, set the class variable recordMode instead.

SnapshotTestCase.recordMode = true

Note that you will probably need to set up a principal class to guarantee that record mode is activated before your test suite is run.

Statement

To explicitly record a single snapshot you can instead use the RecordSnapshot() function:

class ViewTests: SnapshotTestCase {
    
    func testView_withAlteration() {
        // Given
        let view = View(frame: CGRect(x: 0, y: 0, width: 375, height: 100))
        
        // When
        view.alter()
        
        // Then
        RecordSnapshot(view)
    }
    
}

Principal class

A principal class is automatically instantiated by XCTest when your test bundle is loaded. Think of it as a good place to put a global setUp() and tearDown(). A simple principal class might look like this:

import SnapshotTest

class TestObserver : NSObject {

    override init() {
        SnapshotTestCase.recordMode = true
    }
}

In your test bundle's Info.plist, add a key value pair:

<key>NSPrincipalClass</key>
<string>YourAppTests.TestObserver</string>

Where YourAppTests is the name of your test bundle.

This will activate record mode globally and is guaranteed to be run before your test suite.

Options

SnapshotTest provides different ways to compare snapshots using several options.

Option Description
device Compares snapshots specific to a certain device.
osVersion Compares snapshots specific to a certain OS version.

To use one or several options you just pass them to the options argument of the assertion:

AssertSnapshot(view, options: [.device, .osVersion])

Platforms

The following platforms and minimum versions are supported:

  • iOS 8.0
  • tvOS 9.0

Distribution

Use SnapshotTest by building it and integrating it into your project manually or by using a depencency manager. Currently only CocoaPods is supported with more to come.

CocoaPods

Just add the following line to your Podfile in the scope of your test target:

target "MyAppTests" do
  use_frameworks!
  pod 'SnapshotTest' ~> 'X.Y.Z'
end

Replace X.Y.Z with the starting version you wish to use. Breaking backward compatability will be a last resort kind of deal but specifying version is still recommended.

Contribute

SnapshotTest is licensed under the BSD 2-clause License and contributions are very welcome in the form of pull requests and issues.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].