Code coverage. SwiftUI Wrong Executable Lines

Hi community:

I noticed that each closure is counted as lines in code coverage (unit tests) (Xcode 14.1.0) in a swiftUI File. I mean, If you coded and VStack that involves another HStack, and HStack contains 4 lines, and the VStack contains 6 lines counting the HStack. The total executable lines should be 6 (6 lines in the file). But Xcode count 10, counting twice the HStack lines.

Is it a bug, or is it correct? You know, I don't know if Apple has another concept about executable lines.

Also, Is it possible to remove previews with any configuration from code coverage or constant files?

Thanks for all.

I'm seeing the exact same thing, and I can't believe that this post is the only thing I can find online about it! I have one view that's 183 lines, including comments and empty lines, but without the #Preview, and the code coverage table shows that it has 624 lines. It's bad enough that it's well nigh impossible to unit-test SwiftUI views, but wildly inflating their line counts is causing our overall test coverage numbers to be much lower than they should be.

(I've confirmed this in Xcode 16.4 and 26.0.1.)

Code coverage. SwiftUI Wrong Executable Lines
 
 
Q