707 tests are failing because accessibility identifiers are not being generated. Tests expect identifiers but get empty strings.
The AutomaticComplianceModifier uses an EnvironmentAccessor helper view that only executes when the view is actually installed in a view hierarchy. In test environments:
-
ViewInspector: When using
ViewInspector.inspect(), the view might not be fully rendered/installed, so the modifier body never executes. -
Platform View Hosting: When using
UIHostingController/NSHostingControllerin tests without a proper window hierarchy, the view might not be fully rendered, so the modifier body never executes. -
SwiftUI Modifier Lazy Evaluation: SwiftUI modifiers are lazy - they only execute their body when the view is actually rendered. Without proper rendering, identifiers are never generated.
public struct AutomaticComplianceModifier: ViewModifier {
public func body(content: Content) -> some View {
EnvironmentAccessor(content: content) // Helper view
}
private struct EnvironmentAccessor: View {
// Environment access happens here
// Only executes when view is installed in hierarchy
var body: some View {
// Identifier generation happens here
}
}
}- Test creates view with
.automaticCompliance() - Test helper wraps view with environment:
.environment(\.globalAutomaticAccessibilityIdentifiers, true) - View is inspected/hosted
- PROBLEM: Modifier body might not execute if view isn't fully rendered
Force the view to render by:
- Adding the hosting controller to a window/view hierarchy
- Calling layout methods (but this can hang in tests)
- Using a different inspection method
Generate identifiers eagerly when the modifier is applied, not lazily when the view renders.
Create a test-specific path that generates identifiers without requiring full view rendering.
Ensure the environment is properly set up before the view is created, and ensure the config is available via task-local.
- Verify if modifier body is being called in tests
- Check if environment is properly available when modifier runs
- Determine if we need to force rendering or change the approach
- Implement fix based on findings