{"id":2135,"url":"https://github.com/uber/ios-snapshot-test-case","last_synced_at":"2025-05-13T21:12:00.116Z","repository":{"id":28237046,"uuid":"114173355","full_name":"uber/ios-snapshot-test-case","owner":"uber","description":"Snapshot view unit tests for iOS","archived":false,"fork":false,"pushed_at":"2025-01-09T19:36:43.000Z","size":1543,"stargazers_count":1815,"open_issues_count":40,"forks_count":219,"subscribers_count":1102,"default_branch":"main","last_synced_at":"2025-05-13T01:37:05.879Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uber.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-12-13T21:59:37.000Z","updated_at":"2025-05-11T09:42:19.000Z","dependencies_parsed_at":"2024-04-24T09:59:10.155Z","dependency_job_id":"28690575-cf71-4984-b47a-98bbbfd782cc","html_url":"https://github.com/uber/ios-snapshot-test-case","commit_stats":{"total_commits":269,"total_committers":67,"mean_commits":4.014925373134329,"dds":0.8252788104089219,"last_synced_commit":"71f19547d9f9d0959a10881814de41b2114a8e1c"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uber%2Fios-snapshot-test-case","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uber%2Fios-snapshot-test-case/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uber%2Fios-snapshot-test-case/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uber%2Fios-snapshot-test-case/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uber","download_url":"https://codeload.github.com/uber/ios-snapshot-test-case/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254029005,"owners_count":22002283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:05.553Z","updated_at":"2025-05-13T21:11:55.097Z","avatar_url":"https://github.com/uber.png","language":"Objective-C","funding_links":[],"categories":["Testing","Objective-C"],"sub_categories":["Other Testing"],"readme":"# iOSSnapshotTestCase (previously [FBSnapshotTestCase](https://github.com/facebookarchive/ios-snapshot-test-case))\n\n[![Build Status](https://github.com/uber/ios-snapshot-test-case/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/uber/ios-snapshot-test-case/actions)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/iOSSnapshotTestCase.svg)](https://img.shields.io/cocoapods/v/iOSSnapshotTestCase.svg)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Swift Package Manager](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square)](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square)\n\n## What it does\n\nA \"snapshot test case\" takes a configured `UIView` or `CALayer` and uses the necessary UIKit or Core Animation methods to generate an image snapshot of its contents. It\ncompares this snapshot to a \"reference image\" stored in your source code\nrepository and fails the test if the two images don't match.\n\n## Why?\n\nWe write a lot of UI code. There are a lot of edge\ncases that we want to handle correctly when you are creating `UIView` instances:\n\n- What if there is more text than can fit in the space available?\n- What if an image doesn't match the size of an image view?\n- What should the highlighted state look like?\n\nIt's straightforward to test logic code, but less obvious how you should test\nviews. You can do a lot of rectangle asserts, but these are hard to understand\nor visualize. Looking at an image diff shows you exactly what changed and how\nit will look to users.\n\n`iOSSnapshotTestCase` was developed to make snapshot tests easy.\n\n## Installation\n\n### Step 1: Add iOSSnapshotTestCase to your project\n\n#### CocoaPods\n\nAdd the following lines to your Podfile:\n\n```ruby\ntarget \"Tests\" do\n  use_frameworks!\n  pod 'iOSSnapshotTestCase'\nend\n```\n\nIf your test target is Objective-C only use `iOSSnapshotTestCase/Core` instead, which doesn't contain Swift support.\n\n#### Carthage\n\nAdd the following line to your Cartfile:\n\n```carthage\ngithub \"uber/ios-snapshot-test-case\" ~\u003e 8.0.0\n```\n\n#### Swift Package Manager\n\nAdd the following line to your `Package.swift`:\n\n```spm\ndependencies: [\n  .package(url: \"https://github.com/uber/ios-snapshot-test-case.git\", from: \"8.0.0\"),\n],\n```\n\n...or integrate with Xcode via `File -\u003e Swift Packages -\u003e Add Package Dependency...` using the URL of the repository. We recommend using \"Up to Next Major\" with the Version field, as we use Semantic Versioning and only put breaking changes in major versions.\n\n### Step 2: Setup Test Scheme\nReplace \"Tests\" with the name of your test project.\n\n1. There are [three ways](https://github.com/uber/ios-snapshot-test-case/blob/main/src/iOSSnapshotTestCaseCore/Public/FBSnapshotTestCase.h#L17-L31) 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:\n\n|Name|Value|\n|:---|:----|\n|`FB_REFERENCE_IMAGE_DIR`|`$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages`|\n|`IMAGE_DIFF_DIR`|`$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/FailureDiffs`|\n\nDefine the `IMAGE_DIFF_DIR` to the directory where you want to store diffs of failed snapshots. There are also [three ways](https://github.com/uber/ios-snapshot-test-case/blob/main/src/iOSSnapshotTestCaseCore/Public/FBSnapshotTestCase.h#L33-L45) to set failed image diff directories.\n\n![](FBSnapshotTestCaseDemo/Scheme_FB_REFERENCE_IMAGE_DIR.png)\n\n## Creating a snapshot test\n\n1. Subclass `FBSnapshotTestCase` instead of `XCTestCase`.\n2. From within your test, use `FBSnapshotVerifyView`.\n3. Run the test once with `self.recordMode = YES;` in the test's `-setUp`\n   method. (This creates the reference images on disk.)\n4. Remove the line enabling record mode and run the test.\n\n## Features\n\n- Automatically names reference images on disk according to test class and\n  selector.\n- Prints a descriptive error message to the console on failure. (Bonus:\n  failure message includes a one-line command to see an image diff if\n  you have [Kaleidoscope](http://www.kaleidoscopeapp.com) installed.)\n- Supply an optional \"identifier\" if you want to perform multiple snapshots\n  in a single test method.\n- Support for `CALayer` via `FBSnapshotVerifyLayer`.\n- `usesDrawViewHierarchyInRect` to handle cases like `UIVisualEffect`, `UIAppearance` and Size Classes.\n- `fileNameOptions` to control appending the device model (`iPhone`, `iPad`, `iPod Touch`, etc), OS version, screen size and screen scale to the images (allowing to have multiple tests for the same «snapshot» for different `OS`s and devices).\n\n## Notes\n\nYour unit tests _should_ be inside an \"application\" bundle, not a \"logic/library\" test bundle. (That is, it\nshould be run within the Simulator so that it has access to UIKit.)\n\n*However*, if you are writing snapshot tests inside a library/framework, you might want to keep your test bundle as a library test bundle without a Test Host.\n\nRead more on this [here](docs/LibraryVsApplicationTestBundles.md).\n\n## Authors\n\n`iOSSnapshotTestCase` was written at Facebook by\nJonathan Dann with significant contributions by\nTodd Krabach.\n\nToday it is maintained by [Uber](https://github.com/uber).\n\n## License\n\n`iOSSnapshotTestCase` is MIT–licensed. See [`LICENSE`](https://github.com/uber/ios-snapshot-test-case/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuber%2Fios-snapshot-test-case","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuber%2Fios-snapshot-test-case","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuber%2Fios-snapshot-test-case/lists"}