Search code examples
iosxcodecode-coverage

Xcode missing coverage for certain targets


I have a file that is tested by unit tests 100%. After I've run these tests it also shows in the annotated source bar that all lines of code are reached once in unit tests.

However, when I head to the Report Navigator, it shows that this file has 0% coverage in the app's coverage. The only place where it seems to have coverage, is in the test bundle.

How is this possible?

Things i've tried:

  • Clean the project
  • Remove the Derived Data

Other tests have the same target memberships, but their results are visible in the report navigator.


Solution

  • I have solved this issue. The problem was that the project has multiple targets, and a lot of the unit tests derive from a pre-Swift time.

    Only the test files should have target memberships with the test target. Use @testable import in Swift to import the right targets into your tests.