12

I have an Xcode project that does not seem to want to compile my main app target to generate a product prior to attempting to use it as the application host when running unit tests. From Xcode, I am attempting to run unit tests with ⌘ + U.

I immediately get a dialog which states: Could not determine bundle identifier for [app name] TEST_HOST

(Replace [app name] with the real application name)

This dialog also includes a path to my local derived data products directory: "/Users/***/Library/Developer/Xcode/DerivedData/Lowes-aymgdtrbrarmcidtkxoqxeafmxmj/Build/Products/Debug-iphonesimulator/[app name]"

I have unit tests set up with the TEST_HOST setting pointing to $(BUILT_PRODUCTS_DIR)/[app name].app/[app name]. The unit test target has a target dependency on the main app target. The BUNDLE_LOADER setting is set to $(TEST_HOST). If I compile the main app target first by hitting ⌘ + B, the correct directory structure and app are created, and then hitting ⌘ + U bootstraps and runs the unit tests correctly. If I do a clean and try again it immediately fails. I have never run into this issue before, and it seems to have sprung up after the app was converted to Swift 3. This may or may not have any bearing on the problem, not really sure.

I have read through several answers here and tried a lot of the suggestions, but they don't seem to have the same root problem as me. For most people, it seems setting the host application to None and back to the main target fixes the issue. This is not the case for me.

I've tried fresh checkouts, re-converting the app and test targets to Swift 3, and also the standard clean / clean build folder / wipe derived data. None of these seem to have any effect.

Has anyone else experienced this issue and figured out a solution?

Community
  • 1
  • 1
Mark Struzinski
  • 32,945
  • 35
  • 107
  • 137
  • Try to checkout a version before converting, clean project & Derived Data, make sure it's building, convert again, clean project & Derived Data, build. – shallowThought Feb 14 '17 at 21:25
  • Yeah, I've performed all of those steps as part of troubleshooting. Right now it seems that Xcode just refuses to build the app target first. – Mark Struzinski Feb 15 '17 at 13:15
  • Maybe update your question with details of your new findings. I did not understand the issue in your comment "it seems that Xcode just refuses to build the app target first". It does not build a commit previous to the conversion? – shallowThought Feb 15 '17 at 15:23
  • It builds just fine when I am just building and running. But when I try to run tests, it does not build the app target first. – Mark Struzinski Feb 15 '17 at 15:29
  • I experience the same issue – bartosss Mar 29 '17 at 18:32

6 Answers6

19

I found a resolution for this. It might not apply to every scenario, but it fixed mine. In the main project settings on the Info tab, there is an option to select the configuration to run when starting command line builds. Mine was set to Release. Flipping this to Debug fixed my issue.

Xcode Project Settings, Info Tab

Mark Struzinski
  • 32,945
  • 35
  • 107
  • 137
3

Deleting the Test Host completely from the Build Settings of your test target would solve this issue

bartosss
  • 1,030
  • 9
  • 16
  • I tried this step, it had no effect on the issue I experienced for this question. – Mark Struzinski Apr 06 '17 at 12:02
  • Probably because "Test Host" is actually set to be `$(BUNDLE_LOADER)` (this is the default value i think), if you delete the value of "Bundle Loader" that would probably do the work. – Daniel Lahyani Jul 18 '17 at 13:46
0

It seems that setting the "Bundle Loader" in Release configuration solves the problem.

I can't fully understand why but for me this error always appeared in our CI system where we execute the build from command-line. In the project settings we have set "Use Release for command-line builds". Hence I think that even though we set the build configuration to Debug via command-line arguments, xcodebuild is ignoring the configuration argument and is partially using "Release" settings. This is possibly a bug with xcodebuild system (I guess it worth a radar), if anyone can find a better explanation for why this solves the bug I'd love to hear about it.

Hope this helps.

Daniel Lahyani
  • 925
  • 8
  • 15
0

My problem was the Info.plist File setting in Build Settings was non-existent. Updating the setting to the right plist file solved the issue.

Paul Beusterien
  • 27,542
  • 6
  • 83
  • 139
0

Xcode 9.2, Swift 4

In my case, the "URL types" that I had earlier added in Info.plist, and then deleted it again from Info.plist has left the traces in the INFO tab of that target. So I had to manually delete it again.

It doesn't allow to delete URL Types from the Info tab, so go back to Info.plist file and delete that again

Naishta
  • 11,885
  • 4
  • 72
  • 54
0

XCode 9.4.1, Swift 4

Cleaning the Derived data, quitting Xcode, relaunching the Xcode did the trick for me this time.

Naishta
  • 11,885
  • 4
  • 72
  • 54