Browse Questions
  • Address Sanitizer (ASan) is a runtime tool that detects memory corruption bugs — buffer overflows, use-after-free, and invalid memory access — that would otherwise cause mysterious crashes.
  • Snapshot testing captures a reference image of a view and compares future runs against it.
  • An actor is a reference type that protects its mutable state from concurrent access.
  • Encapsulation means bundling data with the operations that act on it, and restricting direct access to that data so internal invariants can't be broken from outside.

Answer: Snapshot testing captures a reference image of a view and compares future runs against it. Any visual change fails the test, catching unintended UI regressions.

Popular library: swift-snapshot-testing by Point-Free

Code Example:

import SnapshotTesting

class ProfileCardTests: XCTestCase {

    func test_profileCard_defaultState() {
        let view = ProfileCardView(user: .mock())
        let vc = UIHostingController(rootView: view)

        // First run — creates reference snapshot
        // Subsequent runs — compares against saved image
        assertSnapshot(matching: vc, as: .image(on: .iPhone13))
    }

    func test_profileCard_premiumBadge() {
        let view = ProfileCardView(user: .mockPremium())
        assertSnapshot(matching: view, as: .image)
    }
}

Workflow:

  1. Write test → run → reference image saved to __Snapshots__ folder
  2. Commit snapshots to git
  3. Future UI changes fail the test — you review and update the snapshot if intentional