-
Notifications
You must be signed in to change notification settings - Fork 4
Shapshot Testing
Most of the views are tested using snapshot testing.
The snapshots are stored in a separate repository spark-ios-snapshots.
The snapshots need to be added as a github submodule.
After cloning the spark-ios repository, switch to the root folder of the project
cd spark-ios
and create the submodle:
git submodule add -f [email protected]:adevinta/spark-ios-snapshots.git spark-ios-snapshots
When working on a feature branch that generates snapshots, create a branch on the spark-ios-snapshots repository with the exact same name. When create a pull request for the feature, also create a pull request for the snapshots. Please add a link of the snapshots pull request to the description of the feature pull request.
The pull request build will check for snapshots in a branch with the exact same name as the feature branch in the spark-ios-snapshots repository.
Only merge the snapshots to main immediately before merging the pull request to main. Merging snapshots to main can break the tests of the main branch, that is why both branches should be merged at almost the same time.
In Spark, all unit tests are kept in the same folder as the files that they test. The test needs to be added to the test target and not the main target.
For snapshot testing UIKit components, there is a helper class UIKitComponentTestCase
which generates snapshots for a variety of sizes and light and dark mode. The test class should extend UIKitComponentTestCase
and use the function assertSnapshotInDarkAndLight
for asserting the tests.
For snapshot testing SwiftUI components, there is a helper class SwiftUIComponentTestCase
which generates snapshots for a variety of sizes and light and dark mode. The test class should extend SwiftUIComponentTestCase
and use the function assertSnapshotInDarkAndLight
for asserting the tests.