Xcode 8 单元测试错误:无法确定 TEST_HOST 的包标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42236105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 8 Unit Test Error: Could Not Determine Bundle Identifier for TEST_HOST
提问by Mark Struzinski
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
.
我有一个 Xcode 项目,在运行单元测试时尝试将其用作应用程序主机之前,它似乎不想编译我的主应用程序目标来生成产品。在 Xcode 中,我尝试使用? + U
.
I immediately get a dialog which states:
Could not determine bundle identifier for [app name] TEST_HOST
我立即得到一个对话框,其中指出:
Could not determine bundle identifier for [app name] TEST_HOST
(Replace [app name] with the real application name)
(将 [app 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]"
此对话框还包括我的本地派生数据产品目录的路径:
"/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.
我设置了单元测试,其中 TEST_HOST 设置指向$(BUILT_PRODUCTS_DIR)/[app name].app/[app name]
. 单元测试目标对主应用程序目标具有目标依赖性。BUNDLE_LOADER 设置设置为$(TEST_HOST)
. 如果我首先通过点击编译主应用程序目标? + B
,则会创建正确的目录结构和应用程序,然后点击? + U
引导程序并正确运行单元测试。如果我清理并重试,它会立即失败。我以前从未遇到过这个问题,在应用程序转换为 Swift 3 后它似乎突然出现。这可能与问题无关,也不确定。
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.
我在这里通读了几个答案并尝试了很多建议,但它们似乎与我没有相同的根本问题。对于大多数人来说,似乎将主机应用程序设置为 None 并返回到主要目标可以解决问题。这不是我的情况。
- Tests stop working under xcode 8 TEST_HOST error
- Could not determine bundle identifier for xxxTest TEST_HOST
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.
我尝试了新的结帐,将应用程序和测试目标重新转换为 Swift 3,以及标准的清理/清理构建文件夹/擦除派生数据。这些似乎都没有任何效果。
Has anyone else experienced this issue and figured out a solution?
有没有其他人遇到过这个问题并找到了解决方案?
回答by Mark Struzinski
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.
我为此找到了解决方案。它可能不适用于所有场景,但它修复了我的问题。在信息选项卡上的主项目设置中,有一个选项可以选择在启动命令行构建时运行的配置。我的设置为发布。将此翻转到 Debug 修复了我的问题。
回答by bartosss
Deleting the Test Host
completely from the Build Settings
of your test target would solve this issue
Test Host
从Build Settings
您的测试目标中完全删除将解决此问题
回答by Daniel Lahyani
It seems that setting the "Bundle Loader" in Release configuration solves the problem.
似乎在 Release 配置中设置“Bundle Loader”可以解决问题。
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 Releasefor 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.
我不能完全理解为什么但对我来说这个错误总是出现在我们从命令行执行构建的 CI 系统中。在项目设置中,我们设置了“使用发行版进行命令行构建”。因此,我认为即使我们通过命令行参数将构建配置设置为调试,xcodebuild
也会忽略配置参数并部分使用“发布”设置。这可能是xcodebuild
系统的错误(我想它值得关注),如果有人能找到更好的解释来解释为什么这可以解决我很想听到的错误。
Hope this helps.
希望这可以帮助。
回答by Paul Beusterien
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.
我的问题是Info.plist File
设置Build Settings
不存在。将设置更新到正确的 plist 文件解决了这个问题。
回答by Naishta
Xcode 9.2, Swift 4
Xcode 9.2,斯威夫特 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 tabof that target. So I had to manually delete it again.
在我的例子中,我之前在 Info.plist 中添加的“URL 类型”,然后再次从 Info.plist 中删除它已经在该目标的INFO 选项卡中留下了痕迹。所以我不得不再次手动删除它。
It doesn't allow to delete URL Types from the Info tab, so go back to Info.plist file and delete that again
它不允许从“信息”选项卡中删除 URL 类型,因此请返回 Info.plist 文件并再次删除它
回答by Naishta
XCode 9.4.1, Swift 4
XCode 9.4.1,Swift 4
Cleaning the Derived data, quitting Xcode, relaunching the Xcode did the trick for me this time.
这次清理派生数据、退出 Xcode、重新启动 Xcode 对我来说都是成功的。