Modern snapshot testing written in Swift.
Used to for testing snapshots of mostly UI components but also models and other types.
It comes with a few predefined matchers:
UIMatcherfor SwiftUI and UIKit snapshots.EncodableMatcherfor snapshots of models encoded to JSON.ReflectionMatcherfor snapshots of any type in the form of a reflection description.
Snapshots can be configured to use the following:
RecordingStrategydetermines how snapshots are saved and read.DiffingStrategyhow to diff the recorded snapshot against the one generated by the test.RenderingStrategystrategy used for rendering UI snapshots.SizingStrategystrategy used for sizing views before snapshotting.
Example of snapshot testing a SwiftUI view:
import XCTest
import Stilleben
final class SomeViewTests: XCTestCase {
private let matcher = UIMatcher()
.assertSimulator(modelIdentifier: "iPhone14,7")
.sizing(.dynamicHeight)
.dynamicTypeSizes(.large)
func testSomeView() async throws {
await matcher
.colorSchemes(.light)
.match {
NavigationView {
SomeView()
}
}
}
}It also supports snapshot testing UIKit view controllers or views:
import XCTest
import Stilleben
final class SomeViewControllerTests: XCTestCase {
private let matcher = UIMatcher()
.assertSimulator(modelIdentifier: "iPhone14,7")
.sizing(.screen)
func testSomeViewController() async throws {
await matcher
.match { @MainActor () -> UIViewController in
SomeViewController()
}
}
func testSomeView() async throws {
await matcher
.sizing(.intrinsic)
.match { @MainActor () -> UIView in
SomeView()
}
}
}