paulz / SwiftUI-snapshot-testing

Practical SwiftUI Snapshot Testing
MIT License
6 stars 1 forks source link

SwiftUI-snapshot-testing

Practical SwiftUI Snapshot Testing

Build and Test

  1. Compare Actual SwiftUI View with expected image with color accuracy
  2. Overwrite Expected with Actual on failure
  3. Attach Image Difference to test failure

This allows simple snapshot tests for SwiftUI views and previews.

Installation

Add Swift Package, add SwiftUI_SnapshotTesting to a project Test target.

Optionally add PreviewGroup to the app target, see Preview Group

Example

See Example iOS app project with SnapshotTests.swift

func testViews() {
    verifySnapshot(FavoriteView_Previews.self)
    verifySnapshot(ContentView())
    verifySnapshot(Text("SwiftUI").foregroundColor(.red), "example")
}

Documentation is on Wiki