6

Summary

I'm trying to get a code coverage report from my project. However when I try to build and run tests, there is no CodeCoverage folder created in the derived data folder.

How am I trying to do this?

I am running xcodebuild as follows:

xcodebuild \ -workspace <some_workspace> \ -scheme <some_scheme> \ -destination <some_destination> \ -derivedDataPath <some_path> \ -enableCodeCoverage YES \ build test

What is the problem?

For my workspace/project it fails at the very end with a line:

xcodebuild: error: Failed to build workspace <some_workspace> with scheme <some_scheme>. Reason: Could not determine bundle identifier for <some_test_target>'s TEST_HOST: "<some_path>/Build/Intermediates/CodeCoverage/Products/Debug-iphonesimulator/<some_product>.app"

At first it seemed directly linked to the TEST_HOST issue, but that's not the case here.

There is simply no CodeCoverage folder:

<some_path>/Build/Intermediates/CodeCoverage

What have I tried?

I tried the same with a clean new project, same running the same xcodebuild command, which succeeds. Within the Build/Intermediates/ folder exists the CodeCoverage folder.

However, in my own project, which is more complex, the Build/Intermediates/ folder contains a bunch of *.build folders (related to the app and the various frameworks, HockeySDK.build for example) and PrecompiledHeaders but no CodeCoverage folder.

When looking through the output of xcodebuild I never see a reference to the CodeCoverage folder for my project. However, for the test project, the first mention is at:

Write auxiliary files /bin/mkdir -p /<some_path>/Build/Intermediates/CodeCoverage/Intermediates/<some_project>.build/Debug-iphonesimulator/<some_project>.build/Objects-normal/x86_64

For my project I see:

Write auxiliary files /bin/mkdir -p /<some_path>/Build/Intermediates/<some_project>.build/Debug-iphonesimulator/<some_project>.build/Objects-normal/x86_64

Workaround

Something else that seemed to 'trick' it into working is to set the Host Application to None. After doing this it builds and tests, but tests fail due to the lack of host. However, this causes the CodeCoverage folder to be created, and if the Host Application is correctly set again, running the build and tests works fine, with a code coverage report produced.

Vamos
  • 2,701
  • 2
  • 24
  • 37
  • The error seems to indicate that it's something to do with your test target scheme. You are running the tests though command line but what does it do if you run the tests through Xcode (make sure code coverage is turned on for the scheme)? – dlbuckley Oct 21 '16 at 14:54
  • I get the same error message "Could not determine bundle identifier for..." certainly seems like a project set up issue, which could well be the problem. Interestingly if I uncheck `Gather coverage data` it builds and runs the tests fine. – Vamos Oct 25 '16 at 07:18
  • Please post /Build/Intermediates/CodeCoverage/Products/Debug-iphonesimulator/.app/info.plist – shallowThought Oct 26 '16 at 09:27
  • Here is the info.plist: http://pastebin.com/raw/9HbtzUxc – Vamos Oct 27 '16 at 10:48
  • 1
    Check this: http://stackoverflow.com/a/39655865/1457385 – shallowThought Oct 27 '16 at 11:45
  • Thanks @shallowThought that was it. The debug product name was named slightly differently, in fact it had a "-" in the name, which was replaced with "_" during the build, I renamed the product name so it's consistent across all schemes/configurations and now it seems to be fine. If you answer this question, even if it's to point to the other question, I'd like to send the bounty to you. – Vamos Oct 27 '16 at 13:08
  • Nice. Happy coding! – shallowThought Oct 27 '16 at 14:36

1 Answers1

2

You have to assure the package name is equal in all configurations. Xcode modifies it in case you are using unsupported characters. For instance Xcode replaces "-" with "_".

In all configurations, go to:

Project -> Build Settings -> Product Module

and set the exact same name without spaces.

shallowThought
  • 19,212
  • 9
  • 65
  • 112