Install the package
In Xcode, add the package URL to the test target that owns your tests. Swift Package Manager projects can add this dependency:
.package(url: "https://github.com/modern-swift-dev/swift-snapshot-testing", from: "2.2.0")Write the assertion
Import SnapshotTesting and call assertSnapshot. Choose a strategy such as .image, .json, or .recursiveDescription.
import SnapshotTesting
import Testing
@MainActor
struct WelcomeTests {
@Test func welcomeScreen() {
assertSnapshot(of: WelcomeViewController(), as: .image)
}
}Record, then compare
A missing reference is recorded automatically and causes the first run to fail. Review the new file, commit it, then run the test again. The next run compares the current value with that reference.
When you intend to replace a reference, record within the smallest useful scope:
withSnapshotTesting(record: .all) {
assertSnapshot(of: WelcomeViewController(), as: .image)
}Next: explore the examples
See XCTest, Swift Testing, inline snapshots, and SwiftUI previews in context.
Open examples