Tests stop working under xcode 8 TEST_HOST error

前端 未结 12 809
暖寄归人
暖寄归人 2020-12-15 15:13

I want to start tests under Xcode 8 and it fail in the beginning. My error is:

Could not determine bundle identifier for MyProjectTest\'s TEST_HOST:

相关标签:
12条回答
  • 2020-12-15 15:46

    This is a bug in Xcode right now. See http://www.openradar.me/28095069.

    0 讨论(0)
  • 2020-12-15 15:47

    I too have a project with several schemes, and each of which builds the app using a separate configuration (Debug, AdHoc, etc.) and a separate product name (MyApp, MyApp_Dev, MyApp_Staging, etc.).

    Thankfully, they all have the same Module name so my unit test source files can simply use @testable import MyApp, regardless of active scheme).

    To overcome the error, I just had to make sure that for each scheme of the app target that I wanted to test, the following two matched:

    1. The App Target's Build Settings > Product Name for that build configuration (.e.g, "Debug"),
    2. The Test Target's Build Settings > Test Host for the same build configuration (the part after $(BUILT_PRODUCTS_DIR)...)

    So, if #1 is (for example):

    MyApp-Debug
    

    , then #2 must be:

    $(BUILT_PRODUCTS_DIR)/MyApp-Debug.app/MyApp-Debug
    

    In my case, my scheme was building the AdHoc configuration with a product name ending with the -DEV (development) suffix, but the test target was looking for a host named ending with a suffix of -STG (staging).

    0 讨论(0)
  • 2020-12-15 15:48

    There is one more case you might encounter. If you need different product names for main target(for example Debug, Staging, Production) - and try to use Xcode Host Application selector, it will write incorrect values to TEST_HOST build setting.

    And while error message you see is about bundle identifier in Debug configuration, Xcode actually complains about TEST_HOST in Release configuration.

    I fixed it by manually changing TEST_HOST build setting. For example, if you have ProductName on main target set to AppDebug in Debug and AppRelease in Release configuration, your TEST_HOST should be following:

    What Xcode sets:

    $(BUILT_PRODUCTS_DIR)/AppDebug.app/AppDebug
    

    What you need to set:

    Debug configuration: $(BUILT_PRODUCTS_DIR)/AppDebug.app/AppDebug
    Release configuration: $(BUILT_PRODUCTS_DIR)/AppRelease.app/AppRelease
    
    0 讨论(0)
  • 2020-12-15 15:48

    My project has many targets so I had to set the Tests Target's Host Application to 'None'. (Xcode 9.2)

    0 讨论(0)
  • 2020-12-15 15:50

    For some reason the "Host Application" setting in the picture below was the problem for me. Selecting the proper target fixed this.

    This ended up modifying the following values in my xcodeproj:

    • BUNDLE_LOADER = "$(TEST_HOST)";
    • TEST_HOST = "$(BUILT_PRODUCTS_DIR)/myappname.app/myappname";
    0 讨论(0)
  • 2020-12-15 15:54

    I ran into this error a lot and eventually discovered that it was caused by varying PRODUCT_NAME between Debug and Release build configurations.

    We were doing this so that the Debug builds had a different app name when installed on the phone (as well as a different bundle id so we could install them side-by-side with the App Store builds).

    We reverted that change and added a new APP_DISPLAY_NAME setting to the build configuration, varied that between build types, and changed the Info.plist to use $(APP_DISPLAY_NAME) instead of $(PRODUCT_NAME).

    After doing that, it's important to go into the test target in the project and make sure the 'Host application' setting in General is actually set to your application.

    0 讨论(0)
提交回复
热议问题