Xcode 14.3: Missing code coverage for private variables in SwiftUI views

We are experiencing missing coverage for private variables in SwiftUI views after update from Xcode 14.3 to Xcode 14.2.

Steps to reproduce:

  1. Create new SwiftUI project in Xcode
  2. Enable code coverage
  3. Modify ContentView to
struct ContentView: View {
    private let title = "Hello, world!"
    
    let text: String
    
    var body: some View {
        VStack {
            Text(title)
            Text(text)
        }
        .padding()
    }
}
  1. Run UITest - CoverageTestTests::testExample
  2. Check coverage in Xcode for ContentView

Actual result: Line private let title = "Hello, world!" is not covered.

Expected result: Line should be covered

Workaround: Generate initialiser for ContentView

    init(text: String) {
        self.text = text
    }

Coverage is correct when initialiser is added explicitly

Test project: https://github.com/yuri-qualtie/CoverageTest

We meant update update from Xcode 14.2 to Xcode 14.3

Xcode 14.3: Missing code coverage for private variables in SwiftUI views
 
 
Q