22.5 · Snapshot tests and UI tests
Snapshot and UI tests are where a suite becomes slow and fragile. Used with care they protect what unit tests cannot see; used carelessly they are the reason people stop trusting red.
Mental model. Make the app start in a known state, give elements stable names, and wait for conditions, not time.
Pictures
Reference images, text snapshots and why they break.
- How do snapshot tests work, and what are their pitfalls: rendering differences, dynamic content, size, and review fatigue?
A snapshot test renders a view (or a value) and compares the result with a stored reference; the first run records it, later runs fail on any difference.…
Driving the app
Identifiers, page objects, launch arguments and stubbing.
- How do you write UI tests that stay stable: accessibility identifiers, page objects, launch arguments, stubbed data and waiting?
A UI test launches the real app in a separate process and drives it through the accessibility tree with XCUIApplication. Stability comes from a few habits.…
More in Testing
- 22.1 · The pyramid, and what not to test
- 22.2 · XCTest and Swift Testing
- 22.3 · Async tests, expectations and controlling time
- 22.4 · Fakes, mocks and the inputs that make tests random
- 22.6 · Testing SwiftUI, tvOS focus, and watchOS logic
- 22.7 · Flakes, hermetic CI, and a quality system for a large team
- 22.8 · Swift Testing in depth: arguments, traits, errors, confirmations, isolation and scoping
- 22.9 · XCTest lifecycle and expectations, Sendable doubles, and the main actor in tests