Right Approach to test SwiftUI Views

How do we test SwiftUI views? Can we test them in Unit testing? If so we don't have proper apis to get the view hierarchy or the required set of objects for testing. We have to rely on using identifier for every object and extract the view with the id?

I have seen many using ViewInspector which extracts the view hierarchy and has apis to test the array of views matching a text etc. But is it using a right approach for extracting views will it have issues when ever the Xcode or Os is upgraded?

Is snapshot testing right approach for swiftUI views?

Replies

Snapshot Testing or using View Inspector, both would do. https://www.kodeco.com/30227776-swiftui-testing-with-viewinspector-for-ios#toc-anchor-008