DoorDash: How to Speed Up SwiftUI Development and Testing Using PreviewSnapshots
Original post How to Speed Up SwiftUI Development and Testing Using PreviewSnapshots
Article Summary
John Flanagan from DoorDash reveals how their team eliminated duplicate code between SwiftUI previews and snapshot tests. The solution? An open-source tool that cuts testing boilerplate to a single line.
DoorDash's iOS Infrastructure team built PreviewSnapshots to solve a common pain point: developers were writing nearly identical code twice when using Xcode Previews and SnapshotTesting together. The library lets teams define view states once and reuse them for both live previews and automated visual regression tests.
Key Takeaways
- Single test assertion now covers all preview configurations automatically
- Complex views with multiple bindings benefit most from shared state definitions
- PreviewSnapshots uses generic state types to bundle input parameters cleanly
- New preview states automatically generate corresponding snapshot tests with zero code changes
PreviewSnapshots eliminates code duplication by letting developers write view configurations once for both Xcode Previews and snapshot testing, reducing what used to require dozens of lines to a single assertion.
Continue reading
This page summarizes “How to Speed Up SwiftUI Development and Testing Using PreviewSnapshots” by DoorDash, published Jan 18, 2023. All credit for the original work goes to the authors.