Skip to content

SwiftUI Previews Are Not Excluded From the Test Coverage Results #11

Open

Description

@PSchmiedmayer

Description

Xcode previews are currently reported as uncovered code in the code coverage report.

Reproduction

Adding a SwiftUI preview (even with the DEBUG #if statement) is still reported in the code coverage, e.g.:

#if DEBUG
struct Example_Previews: PreviewProvider {
    static var previews: some View {
        Example()
    }
}
#endif

The behaviour can also be reproduced in different Spezi Swift Packages, including the diff code coverage in StanfordSpezi/SpeziAccount#6.

Expected behavior

The preview provides (or even the new #Preview macro) should be excluded from the code coverage report based on the TEST active compilation condition. The TEST active compilation condition should be propagated in the compilation for tests, and the DEBUG flag should ensure that the preview provider is built when showing a view in the Xcode preview.

Code of Conduct

  • I agree to follow this project's Code of Conduct and Contributing Guidelines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions