📸 Delightful Swift snapshot testing.

Overview

📸 SnapshotTesting

Swift 5.1 CI @pointfreeco

Delightful Swift snapshot testing.

Usage

Once installed, no additional configuration is required. You can import the SnapshotTesting module and call the assertSnapshot function.

import SnapshotTesting
import XCTest

class MyViewControllerTests: XCTestCase {
  func testMyViewController() {
    let vc = MyViewController()

    assertSnapshot(matching: vc, as: .image)
  }
}

When an assertion first runs, a snapshot is automatically recorded to disk and the test will fail, printing out the file path of any newly-recorded reference.

🛑 failed - No reference was found on disk. Automatically recorded snapshot: …

open "…/MyAppTests/__Snapshots__/MyViewControllerTests/testMyViewController.png"

Re-run "testMyViewController" to test against the newly-recorded snapshot.

Repeat test runs will load this reference and compare it with the runtime value. If they don't match, the test will fail and describe the difference. Failures can be inspected from Xcode's Report Navigator or by inspecting the file URLs of the failure.

You can record a new reference by setting the record parameter to true on the assertion or setting isRecording globally.

assertSnapshot(matching: vc, as: .image, record: true)

// or globally

isRecording = true
assertSnapshot(matching: vc, as: .image)

Snapshot Anything

While most snapshot testing libraries in the Swift community are limited to UIImages of UIViews, SnapshotTesting can work with any format of any value on any Swift platform!

The assertSnapshot function accepts a value and any snapshot strategy that value supports. This means that a view or view controller can be tested against an image representation and against a textual representation of its properties and subview hierarchy.

assertSnapshot(matching: vc, as: .image)
assertSnapshot(matching: vc, as: .recursiveDescription)

View testing is highly configurable. You can override trait collections (for specific size classes and content size categories) and generate device-agnostic snapshots, all from a single simulator.

assertSnapshot(matching: vc, as: .image(on: .iPhoneSe))
assertSnapshot(matching: vc, as: .recursiveDescription(on: .iPhoneSe))

assertSnapshot(matching: vc, as: .image(on: .iPhoneSe(.landscape)))
assertSnapshot(matching: vc, as: .recursiveDescription(on: .iPhoneSe(.landscape)))

assertSnapshot(matching: vc, as: .image(on: .iPhoneX))
assertSnapshot(matching: vc, as: .recursiveDescription(on: .iPhoneX))

assertSnapshot(matching: vc, as: .image(on: .iPadMini(.portrait)))
assertSnapshot(matching: vc, as: .recursiveDescription(on: .iPadMini(.portrait)))

⚠️ Warning: Snapshots must be compared using a simulator with the same OS, device gamut, and scale as the simulator that originally took the reference to avoid discrepancies between images.

Better yet, SnapshotTesting isn't limited to views and view controllers! There are a number of available snapshot strategies to choose from.

For example, you can snapshot test URL requests (e.g., those that your API client prepares).

assertSnapshot(matching: urlRequest, as: .raw)
// POST http://localhost:8080/account
// Cookie: pf_session={"userId":"1"}
//
// email=blob%40pointfree.co&name=Blob

And you can snapshot test Encodable values against their JSON and property list representations.

assertSnapshot(matching: user, as: .json)
// {
//   "bio" : "Blobbed around the world.",
//   "id" : 1,
//   "name" : "Blobby"
// }

assertSnapshot(matching: user, as: .plist)
// <?xml version="1.0" encoding="UTF-8"?>
// <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
// <plist version="1.0">
// <dict>
//   <key>bio</key>
//   <string>Blobbed around the world.</string>
//   <key>id</key>
//   <integer>1</integer>
//   <key>name</key>
//   <string>Blobby</string>
// </dict>
// </plist>

In fact, any value can be snapshot-tested by default using its mirror!

assertSnapshot(matching: user, as: .dump)
// ▿ User
//   - bio: "Blobbed around the world."
//   - id: 1
//   - name: "Blobby"

If your data can be represented as an image, text, or data, you can write a snapshot test for it! Check out all of the snapshot strategies that ship with SnapshotTesting and learn how to define your own custom strategies.

Installation

Xcode 11

⚠️ Warning: By default, Xcode will try to add the SnapshotTesting package to your project's main application/framework target. Please ensure that SnapshotTesting is added to a test target instead, as documented in the last step, below.

  1. From the File menu, navigate through Swift Packages and select Add Package Dependency….
  2. Enter package repository URL: https://github.com/pointfreeco/swift-snapshot-testing.git
  3. Confirm the version and let Xcode resolve the package
  4. On the final dialog, update SnapshotTesting's Add to Target column to a test target that will contain snapshot tests (if you have more than one test target, you can later add SnapshotTesting to them by manually linking the library in its build phase)

Swift Package Manager

If you want to use SnapshotTesting in any other project that uses SwiftPM, add the package as a dependency in Package.swift:

dependencies: [
  .package(name: "SnapshotTesting", url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.9.0"),
]

Next, add SnapshotTesting as a dependency of your test target:

targets: [
  .target(name: "MyApp", dependencies: [], path: "Sources"),
  .testTarget(name: "MyAppTests", dependencies: ["MyApp", "SnapshotTesting"])
]

Carthage

If you use Carthage, you can add the following dependency to your Cartfile:

github "pointfreeco/swift-snapshot-testing" ~> 1.9.0

⚠️ Warning: Carthage instructs you to drag frameworks into your Xcode project. Xcode may automatically attempt to link these frameworks to your app target. SnapshotTesting.framework is only compatible with test targets, so when you first add it to your project:

  1. Remove SnapshotTesting.framework from any non-test target it may have been added to.
  2. Add SnapshotTesting.framework to any applicable test targets.
  3. Add a New Copy Build Phase to any applicable test targets with Destination set to "Frameworks", and add SnapshotTesting.framework as an item to this phase.
  4. Do not add SnapshotTesting.framework to the "Input Files" or "Output Files" of your app target's Carthage copy-frameworks Run Script Phase.

See Carthage's "Adding frameworks to unit tests or a framework" documentation for more.

CocoaPods

If your project uses CocoaPods, add the pod to any applicable test targets in your Podfile:

target 'MyAppTests' do
  pod 'SnapshotTesting', '~> 1.9.0'
end

Features

  • Dozens of snapshot strategies. Snapshot testing isn't just for UIViews and CALayers. Write snapshots against any value.
  • Write your own snapshot strategies. If you can convert it to an image, string, data, or your own diffable format, you can snapshot test it! Build your own snapshot strategies from scratch or transform existing ones.
  • No configuration required. Don't fuss with scheme settings and environment variables. Snapshots are automatically saved alongside your tests.
  • More hands-off. New snapshots are recorded whether isRecording mode is true or not.
  • Subclass-free. Assert from any XCTest case or Quick spec.
  • Device-agnostic snapshots. Render views and view controllers for specific devices and trait collections from a single simulator.
  • First-class Xcode support. Image differences are captured as XCTest attachments. Text differences are rendered in inline error messages.
  • Supports any platform that supports Swift. Write snapshot tests for iOS, Linux, macOS, and tvOS.
  • SceneKit, SpriteKit, and WebKit support. Most snapshot testing libraries don't support these view subclasses.
  • Codable support. Snapshot encodable data structures into their JSON and property list representations.
  • Custom diff tool integration. Configure failure messages to print diff commands for Kaleidoscope (or your diff tool of choice).
    SnapshotTesting.diffTool = "ksdiff"

Plug-ins

Have you written your own SnapshotTesting plug-in? Add it here and submit a pull request!

Related Tools

  • iOSSnapshotTestCase helped introduce screen shot testing to a broad audience in the iOS community. Experience with it inspired the creation of this library.

  • Jest brought generalized snapshot testing to the JavaScript community with a polished user experience. Several features of this library (diffing, automatically capturing new snapshots) were directly influenced.

Learn More

SnapshotTesting was designed with witness-oriented programming.

This concept (and more) are explored thoroughly in a series of episodes on Point-Free, a video series exploring functional programming and Swift hosted by Brandon Williams and Stephen Celis.

Witness-oriented programming and the design of this library was explored in the following Point-Free episodes:

video poster image

License

This library is released under the MIT license. See LICENSE for details.

Comments
  • Snapshots on Apple Silicon devices

    Snapshots on Apple Silicon devices

    It seems that Apple Silicon machines generate snapshots that are slightly different from the ones generated on x86 machines. The problem is very similar to the one where the very same simulator generates different images depending on the OS version.

    The issues persist when running the simulator using Rosetta.

    Taking into account that it’ll be quite common in the near future to have a team of developers with Intel and Apple Silicon architectures… What’s the best way to handle it?

    Thanks

    opened by luisrecuenco 48
  • Perceptual image precision + 90% speed improvement

    Perceptual image precision + 90% speed improvement

    Problem

    The existing image matching precision strategy is not good at differentiating between a significant difference in a relatively small portion of a snapshot, and imperceivable differences in a large portion of the snapshot. For example, these snapshots below show that a 99.5% precision value fails an imperceivable background color change while allowing noticeable changes (text and color) to pass:

    | Reference | Fails | Passes | |:--:|:--:|:--:| | Reference | Fail | Pass | | | Imperceivable background color difference | Significant text and color changes |

    Solution

    This PR adds a new optional perceptualPrecision parameter to image snapshotting which determines how perceptually similar a pixel must be to consider it matching. This parameter complements the existing precision parameter that determines the percentage of pixels that must be considered matching in order to consider the whole image matching.

    This approach is similar to https://github.com/pointfreeco/swift-snapshot-testing/pull/571 and https://github.com/pointfreeco/swift-snapshot-testing/pull/580 but uses perceptual distance rather than Euclidean distance of sRGB values. This is significant because the sRGB color space is not perceptually uniform. Pairs of colors with the same Euclidean distance can have large perceptual differences. The left and right colors of each row have the same Euclidean distance:

    sRGB-Distance

    The perceptualPrecision parameter is the inverse of a Delta E value. The following table can be used to determine the perceptualPrecision that suites your needs:

    Perceptual Precision Value | Description -- | -- 100% | Must be exactly equal ≥ 99% | Allows differences not perceptible by human eyes ≥ 98% | Allows differences possibly perceptible through close observation ≥ 90% | Allows differences perceptible at a glance ≥ 50% | Allows differences when more similar than opposite ≥ 0% | Allows any differences

    This perceptual color difference calculation is performed by the CILabDeltaE CoreImage Filter which is available on macOS 10.13+, iOS 11+, and tvOS 11+. The use of CoreImage to accelerate the image diffing results in a +90% over the existing byte-by-byte comparison.

    ~~Additionally, when macOS 11.0+, iOS 14+, tvOS 14+ is available, the CILabDeltaE filter is joined with the CIColorThreshold and CIAreaAverage filters to accelerate the whole image comparison, resulting in a 97% speed improvement.~~ The CIColorThreshold filter has been backported to 10.13+, iOS 11+, and tvOS 11+ using MPSImageThresholdBinary so the 97% speed improvement is available in all OS versions.

    Benchmarks

    | Byte-Buffer Comparison | CILabDeltaE + MPSImageThresholdBinary + CIAreaAverage | |:--:|:--:| | macOS 10.10+, iOS 11+, tvOS 10+ | macOS 10.13+, iOS 11+, tvOS 11+ | | 0.906s - baseline | 0.025s - 97% speed improvement | | baseline-macOS-10 10-compatible | macOS-11 0-compatible |

    Addressed Issues

    • closes https://github.com/pointfreeco/swift-snapshot-testing/issues/313
    • closes https://github.com/pointfreeco/swift-snapshot-testing/issues/424
    • closes https://github.com/pointfreeco/swift-snapshot-testing/issues/573
      • Thanks to CoreImage acceleration, the perceptual precision comparison is 90-97% faster than the exact pixel precision comparison

    Related PRs

    • https://github.com/pointfreeco/swift-snapshot-testing/pull/288
    • https://github.com/pointfreeco/swift-snapshot-testing/pull/490
    • https://github.com/pointfreeco/swift-snapshot-testing/pull/571
    • https://github.com/pointfreeco/swift-snapshot-testing/pull/580
    opened by ejensen 29
  • No new releases since Apr 2021 - 1.9.0

    No new releases since Apr 2021 - 1.9.0

    Hi folks!

    Why it has no been releases lately? for those who use semantic versions in packages, we can't have the latest fixes unless we point to master, is there any reason behind it?

    Thanks

    opened by alrocha 18
  • Allow for subpixel deviations + improved unoptimized loop execution in image comparison

    Allow for subpixel deviations + improved unoptimized loop execution in image comparison

    Subpixel difference

    Workaround for the issue described in #313 and #424.

    The readme clearly states that the reference-device should be identical to the recorder-device, but as M1 Macs are becoming popular with developers at a different rate to CI & cloud providers, that is becoming increasingly difficult.

    Allow each subpixel (R, G, B) to deviate by up to a certain degree. Currently, a precision: 0.9 means that "90% of the pixels must match 100%". The issues described in particularly #313, where some experience that the pixels deviate by only 1, can be resolved by comparing with subpixelThreshold: 1. Comparing with precision: 0.9, subpixelThreshold: 1 then means "90% of the subpixels' value must be ±1 of the reference".

    Optimization

    When an image comparison memcmp fails and we need to compare each byte of the failing image, the current loop iteration is slow when compiled without optimization on Intel machines.

    My team defaulted to adding custom compiler flags to SnapshotTesting, but the problem can also be diminished significantly by using a more basic loop implementation.

    The difference between looping over a range (current implementation) and looping with a condition can be seen on Godbolt.

    Example in Godbolt
    1. Go to godbolt.org
    2. Change language to Swift
    3. Copy the following code in the left-hand editor
    4. Wait for the compiler
    5. Compare sections LBB1_4-LBB1_10 with LBB3_1
    func byteDiff1(reference: [UInt8], comparison: [UInt8]) -> Bool {
        let maxDiffs = 100
        var diffs = 0
        for byte in 0..<reference.count {
            if reference[byte] != comparison[byte] {
                diffs += 1
                if diffs >= maxDiffs {
                    return false
                }
            }
        }
        return true
    }
    
    func byteDiff2(reference: [UInt8], comparison: [UInt8]) -> Bool {
        let maxDiffs = 100
        var diffs = 0
        var byte = 0
        while byte < reference.count {
            if reference[byte] != comparison[byte] {
                diffs += 1
                if diffs >= maxDiffs {
                    return false
                }
            }
            byte += 1
        }
        return true
    }
    
    opened by pimms 18
  • Snapshot taken on CI has slight color differences compared to local

    Snapshot taken on CI has slight color differences compared to local

    Hi everybody, I'm having an issue here with color discrepancies in an image view. I'm using KIF framework for UI Tests and SnapshotTesting to take screenshots between interactions (asserts made on the app key window). Everything works fine, except that I get color differences from snapshots taken on my local machine vs snapshots taken on CI machine (both running the same stack, Mojave + Xcode 11.3).

    Some examples below:

    This one is taken by CI machine asdf

    This one is taken by my local computer testOpenAndClose 1

    This is the comparison of both images made by imagemagick result

    And these are the color discrepancies of a same pixel, measured by macOS Digital Color Meter WhatsApp Image 2020-03-17 at 10 11 38 WhatsApp Image 2020-03-17 at 10 11 22

    I know there are lots of variables and also using KIF, but do you guys have any idea of what might be causing this difference?

    Thanks!

    opened by edulpn 18
  • Fix macOS Catalina issue

    Fix macOS Catalina issue

    The problem is that rendering system on different hardwares with the same macOS Catalina version may produce not matched image snapshots. There may be several bytes that have difference just of 1, e.g. in one bitmap some byte has value 212 and in other bitmap the same byte has value 213. Such difference isn't visible by eye even in generated difference_<uuid>.png image. So snapshots generated on developer computer always fail on CI computer. The solution is to ignore the difference of 1 and fail only in case if difference greater than 1.

    opened by maxx-cyber 17
  • Podspec missing in version 1.10.0

    Podspec missing in version 1.10.0

    Describe the bug Podspec missing in version 1.10.0. Cocoapods is still widely used in the industry. Many other dependencies don't have SPM support, which makes it even harder if some others only support SPM..

    To Reproduce run pod install with version 1.10.0

    Expected behavior version 1.10.0 should support Cocoapods to prevent headaches. Please add the support back, we waited so long for the m1 fix 🙏

    opened by egarni 13
  • Custom delegate on WKWebView is replaced by mock when snapshotting

    Custom delegate on WKWebView is replaced by mock when snapshotting

    When a user sets a custom navigation delegate on a WKWebView and makes a snapshot of a view containing this web view, the navigation delegate may be replaced by a stub that makes sure the snapshotting lib knows when to snapshot the web view. This works great when users don't implement a custom WKNavigationDelegate themselves. But when a user implements a custom delegate themselves this fails.

    Consider for example a custom delegate that limits the web view to github.com and opens the browser as soon as the user taps on a link outside of github.com

    class GithubNavigationDelegate: NSObject, WKNavigationDelegate {
      override init() { }
    
      public func webView(
        _ webView: WKWebView,
        decidePolicyFor navigationAction: WKNavigationAction,
        decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
      ) {
        // limit to webpages on to github.com
        guard navigationAction.request.url?.host == "github.com" else {
          decisionHandler(.cancel)
          // Warn user and open url in browser instead
          return
        }
    
        decisionHandler(.allow)
      }
    }
    
    
    webview.navigationDelegate = GithubNavigationDelegate()
    

    This can't be snapshot tested at the moment because the delegate is removed as soon as a snapshot is made.

    I think this could be fixed by retaining the original delegate, implementing all the possible delegate methods and forwarding all the calls to the original delegate. I'll see if I can draft up a PR. Please let me know if you think of another way of dealing with this issue.

    Finally, many thanks for all the work on this great lib 👏🏼 so far, hopefully I can contribute back a bit.

    opened by teameh 13
  • Continuous Integration

    Continuous Integration

    What do you recommend for using this with continuous integration? If the images need to be stored and then subsequently re-run so a comparison can be made, then how would you typically configure your CI setup to keep these images around? I appreciate that there are many CI tools out there and I'm not suggesting specifics. Just some general guidance in the README would be great. Thanks.

    opened by nashysolutions 13
  • The file

    The file "Test.swift" doesn’t exist

    Can not make SnapshotTesting work. When I use assertSnapshot(matching: view, as: .image) I get this message "The file "failed "Test.swift" doesn’t exist"

    What I can do ?

    help wanted 
    opened by upeugene 13
  • Escaped characters detection in literals

    Escaped characters detection in literals

    Followup of https://github.com/pointfreeco/swift-snapshot-testing/pull/228, Fixes https://github.com/pointfreeco/swift-snapshot-testing/issues/230

    This PR fixes inline snapshot tests containing special characters. AssertInlineSnapshot now checks whether the snapshot contains special characters or not. If it does, escapes the snapshot literal appropriately.

    Known issue: AssertInlineSnapshot still searches only for "" and multiline string literals (it does not search #""" """# for example)

    opened by ferranpujolcamins 11
  • Improve wkWebView.takeSnapshot with Xcode 14

    Improve wkWebView.takeSnapshot with Xcode 14

    This will improve https://github.com/pointfreeco/swift-snapshot-testing/issues/625 a bit.

    Without this patch snapshots crash, with this patch, only the background color of the webview is snapped.

    opened by teameh 0
  • 1.10 Breaks automatic naming with Quick testing Framework

    1.10 Breaks automatic naming with Quick testing Framework

    With the addition of CleanCounterBetweenTestCases in 1.10 to support multiple runs of tests popular testing framework Quick no longer works.

    Quick lets users specify test cases declaratively and creates multiple tests from the same function. So when I specify multiple snapshots within one spec() function the counterMap gets reset inbetween each one breaking the automatic naming.

    I understand we want this feature to support the new feature of re running tests, but would it be possible to give users some more flexibility as to when the counterMap gets reset or the ability to turn it off?

    Environment

    • swift-snapshot-testing: 1.10
    • Xcode: 14.2
    • OS: iOS 16
    opened by BoOelkers 0
  • Improve diffs for landscape orientation

    Improve diffs for landscape orientation

    When snapshot testing screenshots in landscape orientation, the diffs are very noisy as the original orientation of the reference image is ignored and it is treated, for the purpose of the visual diff, as a portrait orientation image. (The actual comparison seems to work correctly in a pass/fail sense, however.)

    Unfortunately, this makes it very hard to see what actually changed. For example when removing a button in a drawing app I am currently working on, this is the diff I receive in the current version of the repository: awful_diff

    I believe this issue can be resolved by using the orientation from the new image for the visual diff which results in the following much more readable output: sane_diff

    I don't have enough context to know if my solution has drawbacks for the library/community as a whole so I would certainly appreciate review/discussion to see if there is a better solution.

    opened by Christopher-Thiebaut 0
  • SwiftUI, iOS16: LazyVGrid wrapped into NavigationView is not displayed correctly

    SwiftUI, iOS16: LazyVGrid wrapped into NavigationView is not displayed correctly

    Describe the bug SwiftUI, iOS16: LazyVGrid wrapped into NavigationView is not displayed correctly when using verifySnapshot. Works correctly on iOS15

    To Reproduce SwiftUI, iOS16: Wrap LazyVGrid into NavigationView -> LazyVGrid displayed incorrectly.

    FYI: Outside of the NavigationView, LazyVGrid displayed correctly.

    verifySnapshot(matching: view, as: .image(layout: .device(config: .iPhoneX)), testName: testName)
    
    

    Expected behavior LazyVGrid content is displayed correctly when placed in NavigationView on a snapshot

    Screenshots Actual Result: actual_result Expected Result: expected_result

    Environment

    • swift-snapshot-testing version [1.9.0]
    • Xcode [14.1]
    • Swift [5.7]
    • OS: [iOS 16.0]
    opened by antonhudz 0
  • Add dumpWith to enable further transformations of the generated string with dump

    Add dumpWith to enable further transformations of the generated string with dump

    I've had some issues with some objects, where a memory address would not be correctly erased. I think it would be better if this was customizable from the outside, because right now there doesn't seem to be any way to customize the output of the snap function. What do you think?

    opened by buscarini 0
  • Form isn't rendered properly in Snapshot

    Form isn't rendered properly in Snapshot

    Describe the bug Form isn't being rendered properly in Snapshots.

    To Reproduce Used this code

    // And/or enter code that reproduces the behavior here.
    class SampleSnapshotTest: XCTestCase {
        
        func testDefault() {
            let vc = UIHostingController(rootView: SampleForm())
            vc.view.frame = UIScreen.main.bounds
            
            assertSnapshot(matching: vc, as: .image)
        }
    }
    
    struct SampleForm: View {
        
        var body: some View {
            Form {
                Section {
                    Text("Item1")
                    Text("Item1")
                    Text("Item1")
                    Text("Item1")
                    Text("Item1")
                } header: {
                    Text("Header")
                }
            }
        }
    }
    

    Expected behavior スクリーンショット 2022-12-16 15 06 28

    Screenshots

    Environment

    • swift-snapshot-testing version 1.10.0
    • Xcode Version 14.2 (14C18)
    • Swift 5.7.2
    • OS: 16.2
    opened by surajsau 0
Releases(1.10.0)
  • 1.10.0(Sep 22, 2022)

    Changes that may affect your build requirements

    • The package name has been changed from SnapshotTesting to swift-snapshot-testing, to better reflect community naming conventions (https://github.com/pointfreeco/swift-snapshot-testing/pull/555). This may require you to update any Package.swift files that depend on Snapshot Testing.
    • Support for CocoaPods and Carthage has been obsoleted. No new releases will be available on those platforms, starting with 1.10.0. Please use the Swift Package Manager to depend on Snapshot Testing.
    • Snapshot Testing now requires Swift 5.5+, as well at iOS 13+, macOS 10.15+, tvOS 13+, and watchOS 6+.

    Changes that may affect snapshot format/output

    Warning: The following updates change how a strategy may output a snapshot, causing existing snapshot suites to fail. When upgrading, please rerecord your failing snapshots and audit the changes.

    • Fixed: A UIViewController strategy was not passing along the correct trait collection (thanks @arnopoulos, https://github.com/pointfreeco/swift-snapshot-testing/pull/554).
    • Fixed: iPhone XS Max portrait configuration was not applying base traits (thanks @imvm, https://github.com/pointfreeco/swift-snapshot-testing/pull/417)
    • Fixed: URLRequest strategy now sorts query items for more consistent diffing (thanks @mihai8804858, https://github.com/pointfreeco/swift-snapshot-testing/pull/491).
    • Removed: GLKView is no longer supported (thanks @jpsim, https://github.com/pointfreeco/swift-snapshot-testing/pull/507).

    Everything else

    • Added: Image-based strategies have a new perceptualPrecision option, which can be used to support snapshot tests across Intel and M1 devices. Along for the ride is a 90+% speed improvement to the strategies (thanks @ejensen, https://github.com/pointfreeco/swift-snapshot-testing/pull/628).
    • Added: Windows support, CI (thanks @MaxDesiatov, https://github.com/pointfreeco/swift-snapshot-testing/pull/532).
    • Added: Failure messages now include the snapshot name, if given (thanks @calda, https://github.com/pointfreeco/swift-snapshot-testing/pull/547).
    • Added: iPhone 13 configs (thanks @luispadron, https://github.com/pointfreeco/swift-snapshot-testing/pull/603).
    • Added: iPad 9.7" and iPad 10.2" configs (thanks @skols85, https://github.com/pointfreeco/swift-snapshot-testing/pull/405).
    • Added: iPhone 12 and iPhone 12 Pro Max configs(thanks @imvm, https://github.com/pointfreeco/swift-snapshot-testing/pull/418).
    • Added: Snapshotting.json for Any value (thanks @NachoSoto, https://github.com/pointfreeco/swift-snapshot-testing/pull/552).
    • Added: Newly-recorded snapshots are now attached to the test run (thanks @marcelofabri, https://github.com/pointfreeco/swift-snapshot-testing/pull/586).
    • Fixed: the UIImage strategy was using the device scale instead of the scale of the given images (thanks @codeman9, https://github.com/pointfreeco/swift-snapshot-testing/pull/472).
    • Fixed: the UIImage strategy now compares image contexts using the same colorspace (thanks @dflems, https://github.com/pointfreeco/swift-snapshot-testing/pull/446).
    • Fixed: the WebView strategy no longer overrides the delegate (thanks @teameh in https://github.com/pointfreeco/swift-snapshot-testing/pull/443).
    • Fixed: Patched a leak when running tests in a host application (thanks @llinardos, https://github.com/pointfreeco/swift-snapshot-testing/pull/511).
    • Fixed: False positive when asserting reference image with empty image (thanks @nuno-vieira, https://github.com/pointfreeco/swift-snapshot-testing/pull/453).
    • Fixed: watchOS compilation (thanks @aydegee, https://github.com/pointfreeco/swift-snapshot-testing/pull/579).
    • Fixed: Support for repeatedly running tests (thanks @krzysztofpawski, https://github.com/pointfreeco/swift-snapshot-testing/pull/585).
    • Infrastructure: Add swift-snapshot-testing-stitch to plugins list (thanks @Sherlouk, https://github.com/pointfreeco/swift-snapshot-testing/pull/483)
    • Infrastructure: Document diff tool configuration.
    • Infrastructure: README updates (thanks @MaatheusGois, @gohanlon), documentation fixes (thanks @heckj, @valeriyvan).
    • Infrastructure: Added GitHub issue templates (https://github.com/pointfreeco/swift-snapshot-testing/pull/556).
    • Infrastructure: Add SnapshotTestingHEIC to plugins list (thanks @alexey1312, https://github.com/pointfreeco/swift-snapshot-testing/pull/561).

    New Contributors

    • @arietis made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/468
    • @codeman9 made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/472
    • @Nikoloutsos made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/482
    • @mihai8804858 made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/491
    • @dflems made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/446
    • @skols85 made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/405
    • @imvm made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/418
    • @teameh made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/443
    • @MaatheusGois made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/496
    • @calda made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/547
    • @MaxDesiatov made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/532
    • @jpsim made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/507
    • @arnopoulos made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/554
    • @llinardos made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/511
    • @heckj made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/601
    • @aydegee made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/579
    • @valeriyvan made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/630
    • @ejensen made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/628
    • @luispadron made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/603
    • @alexey1312 made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/561
    • @gohanlon made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/592
    • @marcelofabri made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/586
    • @nuno-vieira made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/453
    • @krzysztofpawski made their first contribution in https://github.com/pointfreeco/swift-snapshot-testing/pull/585

    Full Changelog: https://github.com/pointfreeco/swift-snapshot-testing/compare/1.9.0...1.10.0

    Source code(tar.gz)
    Source code(zip)
  • 1.9.0(Apr 27, 2021)

    • Added: publicized data snapshotting strategy (thanks @regexident).
    • Speed up NSImage comparison (thanks @finestructure, @JaapWijnen).
    • Fixed: enabled testing search paths (thanks @thedavidharris).
    • Infrastructure: links for AccessibilitySnapshot and AccessibilitySnapshotColorBlindness (thanks @Sherlouk).
    Source code(tar.gz)
    Source code(zip)
  • 1.8.2(Aug 20, 2020)

    • Rename SnapshotTesting.record to SnapshotTesting.isRecording to avoid clash with XCTestCase's new record method (thanks @xavierLowmiller).
    • Fix UIApplication selector to return the application as expected (thanks @mstultz).
    • Fix key window warning (thanks @tinder-maxwellelliott)
    Source code(tar.gz)
    Source code(zip)
  • 1.8.1(Jun 19, 2020)

  • 1.8.0(Jun 12, 2020)

    • Added: SwiftUI support (thanks @natemann, @regexident).
    • Added: Apple TV 4K support (thanks @reez).
    • Added: Mac Catalyst support (thanks @rjchatfield).
    • Added: UIBezierPath, NSBezierPath, CGPath strategies (thanks @regexident).
    • Improved: don't crash on empty images, instead produce error artifact (thanks @mackoj).
    • Bug fixed: trait collection now passed to view controller's recursive description strategy (thanks @erikpoort).
    • Bug fixed: will no longer crash on hidden/unloaded web views (thanks @stuaustin).
    • Bug fixed: don't re-add view controller to window when already added (thanks @hassfers).
    • More test coverage (thanks @SatoTakeshiX, @sidepelican).
    • Typos fixed (thanks @freak4pc, @jstart).
    • Other improvements: timeout error messaging, installation instructions, troubleshooting instructions, Linux CI.
    Source code(tar.gz)
    Source code(zip)
  • 1.7.2(Feb 7, 2020)

  • 1.7.1(Dec 15, 2019)

  • 1.7.0(Dec 11, 2019)

    What's new?

    • New snapshot strategy: wait (#268)

    What's improved?

    • Performance improvement: don't diff during recording (#250)
    • Documentation improvement: Xcode 11 installation instructions (#256)
    • NSView rendering improvements (#260)
    • Documentation improvement: SPM test dependency instructions (#265)
    • cURL rendering improvements (#273)

    Thanks to @mr-v, @f-meloni, @schwmi, @freak4pc, and @ldstreet for contributing to this release!

    Source code(tar.gz)
    Source code(zip)
  • 1.6.0(Sep 25, 2019)

    What's changed since last time?

    • Add device sizes for split view variants of iPads (#209)
    • Add recording to inline snapshotting (#212)
    • Sort cURL strategy headers (#214)
    • Add iOS minimum required deployment target to Package.swift (#215)
    • Allow dynamic size of views based on trait collection content sizes (#217)
    • Disable bitcode (#221)
    • Improve _assertInlineSnapshot ergonomics and tests (#231 and #232)
    • Use URL.init(fileURLWithPath:isDirectory:) to avoid file IO (#236)
    • Speed up image diffing (#248)
    • Improve image diff drawing performance (#249)

    Thanks to @Sherlouk, @crayment, @jayhickey, @MarianaMeireles, @pavel-y-ivanov, @ferranpujolcamins, @kirillyakimovich, and @mr-v for making this release happen!

    Source code(tar.gz)
    Source code(zip)
  • 1.5.0(Mar 29, 2019)

    What's new

    • @rjchatfield has introduced (#199) a brand new way of snapshotting textual information, called "inline snapshot testing," which automatically inlines snapshots directly in your test file. The 1.5.0 release includes a preview of this functionality! You can use the _assertInlineSnapshot helper to try it out. Thanks to @rjchatfield for the PR, and find out more here.

    • Two new URLRequest snapshot strategies have been included. First, @Sherlouk has included a curl snapshotting strategy (#203), which snapshots your prepared requests in the cURL format. Also we now have a snapshot strategy for capturing a URLRequest with its body pretty printed, when possible (#157). This helps make POST requests more easily inspectable in the reference file.

    Source code(tar.gz)
    Source code(zip)
  • 1.4.0(Mar 26, 2019)

    This release brings SnapshotTesting up to date with Swift 5!

    What's changed?

    • Swift 5 support!
    • The SnapshotTestCase subclass is no longer needed on Linux and has been deprecated as a type alias to XCTestCase. The type alias will be removed in a future version (#200).
    • The dump strategy has been optimized (#195).
    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(Mar 14, 2019)

    What's new?

    • A new view configuration for the 11" iPad Pro's resolution and safe area (#187).
    • A few let properties on Snapshotting and Diffing have been relaxed to be vars to make it easier to build strategies from existing ones (#189).
    • The UIImage diff message has been generalized to read nicely while in record mode (#188).
    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Feb 20, 2019)

    What's new?

    • Small updates to failure messages https://github.com/pointfreeco/swift-snapshot-testing/pull/153
    • Renamed generics in pullback https://github.com/pointfreeco/swift-snapshot-testing/pull/154
    • Support asserting against multiple strategies at once https://github.com/pointfreeco/swift-snapshot-testing/pull/150
    • Make XCTAttachment's initializers public #159
    • Create a typealias for SnapshotTestCase when not on Linux #169
    • Specify custom snapshot directory #170
    • Extract image diffing strategies. #172
    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Dec 18, 2018)

    What's new?

    • Updated UIView and UIViewController recursiveDescription strategies to support custom trait collections and configuration (#141)
    • Added a new UIViewController hierarchy snapshot strategy (#139)
    • Added a new func strategy on functions that take CaseIterable values (#94)
    • Added a new description strategy powered by String.init(describing:) (#94)
    • Show diff when recording over previous snapshot (#147)

    What's been fixed?

    • Improved the assertSnapshot function's generic names (#120)
    • Improved the recording failure message (#135, #140)
    • Fixed a crash when snapshotting view controllers with main views configured with auto layout (#142)
    • Fixed a crash when running swift test against a failing snapshot (#143)
    Source code(tar.gz)
    Source code(zip)
Owner
Point-Free
A video series exploring Swift and functional programming.
Point-Free
iOS Simulator type agnostic snapshot testing, built on top of the FBSnapshotTestCase.

SnappyTestCase iOS Simulator type agnostic snapshot testing, built on top of the FBSnapshotTestCase. Why? Snapshot testing helps to deliver views that

Tooploox 15 Oct 11, 2019
Testing the UI without UI Testing, a Swift experiment.

UI tests without UI Testing experiment This repo is a small experiment to see if there's an "in-between" for testing iOS applications. More feature-le

Joe Masilotti 20 Sep 26, 2022
SwiftCheck is a testing library that automatically generates random data for testing of program properties

SwiftCheck QuickCheck for Swift. For those already familiar with the Haskell library, check out the source. For everybody else, see the Tutorial Playg

TypeLift 1.4k Dec 21, 2022
Switchboard - easy and super light weight A/B testing for your mobile iPhone or android app. This mobile A/B testing framework allows you with minimal servers to run large amounts of mobile users.

Switchboard - easy A/B testing for your mobile app What it does Switchboard is a simple way to remote control your mobile application even after you'v

Keepsafe 287 Nov 19, 2022
Upload failing iOS snapshot tests cases to S3

Second Curtain If you're using the cool FBSnapshotTestCase to test your iOS view logic, awesome! Even better if you have continuous integration, like

Ash Furrow 129 Sep 6, 2022
Snapshot view unit tests for iOS

iOSSnapshotTestCase (previously FBSnapshotTestCase) What it does A "snapshot test case" takes a configured UIView or CALayer and uses the necessary UI

Uber Open Source 1.7k Jan 4, 2023
Network testing for Swift

DVR DVR is a simple Swift framework for making fake NSURLSession requests for iOS, watchOS, and OS X based on VCR. Easy dependency injection is the ma

Venmo 650 Nov 3, 2022
The Swift (and Objective-C) testing framework.

Quick is a behavior-driven development framework for Swift and Objective-C. Inspired by RSpec, Specta, and Ginkgo. // Swift import Quick import Nimbl

Quick 9.6k Dec 31, 2022
Implementing and testing In-App Purchases with StoreKit2 in Xcode 13, Swift 5.5 and iOS 15.

StoreHelper Demo Implementing and testing In-App Purchases with StoreKit2 in Xcode 13, Swift 5.5, iOS 15. See also In-App Purchases with Xcode 12 and

Russell Archer 192 Dec 17, 2022
Network testing à la VCR in Swift

Vinyl Vinyl is a simple, yet flexible library used for replaying HTTP requests while unit testing. It takes heavy inspiration from DVR and VCR. Vinyl

null 271 Dec 21, 2022
UI Testing Cheat Sheet and Examples.

UI Testing Cheat Sheet This repository is complementary code for my post, UI Testing Cheat Sheet and Examples. The post goes into more detail with exa

Joe Masilotti 2.1k Dec 25, 2022
Mockingbird was designed to simplify software testing, by easily mocking any system using HTTP/HTTPS

Mockingbird Mockingbird was designed to simplify software testing, by easily mocking any system using HTTP/HTTPS, allowing a team to test and develop

FARFETCH 183 Dec 24, 2022
Automatic testing of your Pull Requests on GitHub and BitBucket using Xcode Server. Keep your team productive and safe. Get up and running in minutes. @buildasaur

Buildasaur Automatic testing of your Pull Requests on GitHub and BitBucket using Xcode Server. Keep your team productive and safe. Get up and running

Buildasaurs 774 Dec 11, 2022
Fastbot is a model-based testing tool for modeling GUI transitions to discover app stability problems

Fastbot is a model-based testing tool for modeling GUI transitions to discover app stability problems. It combines machine learning and reinforcement learning techniques to assist discovery in a more intelligent way.

Bytedance Inc. 446 Dec 29, 2022
Genything is a framework for random testing of a program properties.

Genything is a framework for random testing of a program properties. It provides way to random data based on simple and complex types.

Just Eat Takeaway.com 25 Jun 13, 2022
For Testing APIs of NYTimes

NYTimes-APIs For Testing APIs of NYTimes Mark Dennis Diwa ?? To run the app: Open terminal first then run pod install. Open workspace. Run the app on

Mark Dennis Diwa 0 Nov 23, 2021
A Mac and iOS Playgrounds Unit Testing library based on Nimble.

Spry Spry is a Swift Playgrounds Unit Testing library based on Nimble. The best thing about Spry is that the API matches Nimble perfectly. Which means

Quick 327 Jul 24, 2022
Multivariate & A/B Testing for iOS and Mac

This library is no longer being maintained. You can continue to use SkyLab in your projects, but we recommend switching another solution whenever you

Mattt 792 Dec 15, 2022
Remote configuration and A/B Testing framework for iOS

MSActiveConfig v1.0.1 Remote configuration and A/B Testing framework for iOS. Documentation available online. MSActiveConfig at a glance One of the bi

Elevate 78 Jan 13, 2021