SnapshotTestingMacros is a thin layer over swift-testing and swift-snapshot-testing to allow for macro based snapshots using a syntax similar to Swift Testing.
Just as Swift Testing has @Suite and @Test, SnapshotTestingMacros uses @SnapshotSuite and @SnapshotTest to mark up code.
This allows for snapshots to quickly be created by simply marking up functions that return views.
In the simplest case this is all that's needed for a snapshot test:
// ✅ Create a simple snapshot test for some SwiftUI text.
@Suite
@SnapshotSuite
struct MySnapshots {
@SnapshotTest
func myView() -> some View {
Text("Some text")
}
}Note that while
@Suiteisn't explicitly needed to run the snapshots, it's currently recommneded so Xcode can pickup the generated Suite inside the macro. Due to macro limitations it seems that Xcode cannot see Suites when they're embedded inside macro expansion code.
- Usage - Basic usage, example code, and async support.
- Traits - Customising snapshots with traits (sizes, themes, padding, etc.).
- Parameterised Tests - Creating snapshots for multiple configurations.
- SwiftUI: Any view conforming to
View - UIKit (iOS, tvOS, visionOS):
UIView,UIViewController - AppKit (macOS):
NSView,NSViewController
For detailed instructions on running tests, please see CONTRIBUTING.md.
This project uses mise to manage development tools.
See CONTRIBUTING.md for detailed setup and guidelines.