pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.

Home Page:https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optimizing Image Handling in Swift Snapshot Testing

Life-run9723 opened this issue · comments

Hi,
I am using this awesome library for snapshot testing in an iOS project and facing a couple of challenges related to image management and comparison.

Managing Baseline and New Failed Images:
In my snapshot tests, I initially set isRecording to true to capture the baseline image. For example:

func testExampleSnapshot() {
    let view = CustomView(viewModel: .fixture()).background(Color.white)
    let controller = UIHostingController(rootView: view)
    controller.view.backgroundColor = .systemYellow

    isRecording = true
    SnapshotTesting.diffTool = "ksdiff"
    assertSnapshot(matching: controller, as: .image)
}

This works well for creating the baseline image. However, when a change in the view causes the snapshot test to fail, the newly generated failed image is saved in a different location from the baseline image. This necessitates a manual search to find and compare the new failed image, which is quite time-consuming.

Is there a more streamlined process for this? Ideally, I'd like the new failed image to be automatically saved in the same folder as the baseline image. This would allow for easier comparison using tools like SourceTree, without the need to toggle isRecording between true and false for updating the baseline. Any suggestions for a more efficient approach would be greatly appreciated.

Organizing Snapshot Images:
Currently, the baseline images are stored in multiple folders within the snapshot folder, corresponding to each test file. This results in numerous directories containing these images.

Is there a more organized way to handle this? Perhaps storing all images in a single folder, categorized by test class name or function, might be more manageable. I'm seeking advice on the best practices for efficiently organizing these snapshot images in a professional setup.

Any insights or suggestions on these issues would be greatly appreciated!