A library for runtime introspection and unit testing of SwiftUI views, enabling direct access to view hierarchy and state.
ViewInspector is a library for unit testing SwiftUI views by enabling runtime introspection of the view hierarchy. It allows developers to access and verify the underlying View structs and their state, solving the problem of testing SwiftUI view outputs.
iOS, macOS, tvOS, watchOS, and visionOS developers using SwiftUI who need to write comprehensive unit tests for their UI components.
Developers choose ViewInspector because it provides direct access to SwiftUI view internals using official Swift reflection APIs, supports testing of various state types, and enables simulation of user interactions without relying on private APIs.
Runtime introspection and unit testing of SwiftUI views
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses Swift's official reflection APIs, not private ones, ensuring safety for production test targets as emphasized in the README's philosophy section.
Supports reading and verifying @Binding, @State, @ObservedObject, and @EnvironmentObject, enabling deep state verification for custom views, as detailed in the use cases.
Allows programmatic triggering of callbacks like button taps and onAppear events for testing side effects, with examples provided in the README's use cases.
Offers find functions to search for views by type or condition, facilitating targeted assertions in complex hierarchies, as shown in the dynamic querying feature.
The library does not support all SwiftUI views and modifiers, requiring developers to check the API coverage document or contribute fixes, as acknowledged in the contributions section.
Must be added exclusively to the unit test target, which can complicate build configurations and restrict usage in integration or UI automation testing scenarios.
Runtime reflection and hierarchy traversal might introduce slowness in tests with very deep or complex view trees, though not explicitly stated, it's a common trade-off with such introspection.