测试在 xcode 8 TEST_HOST 错误下停止工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39492974/
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
Tests stop working under xcode 8 TEST_HOST error
提问by Jakub
I want to start tests under Xcode 8 and it fail in the beginning. My error is:
我想在 Xcode 8 下开始测试,但一开始就失败了。我的错误是:
Could not determine bundle identifier for MyProjectTest's TEST_HOST: "/Users/jakubmazur/Library/Developer/Xcode/DerivedData/MyProject-ejeepybggxvekxajlyngopeahiex/Build/Intermediates/CodeCoverage/Products/Testing-iphonesimulator/MyProject.app"
无法确定 MyProjectTest 的 TEST_HOST 的包标识符:“/Users/jakubmazur/Library/Developer/Xcode/DerivedData/MyProject-ejeepybggxvekxajlyngopeahiex/Build/Intermediates/CodeCoverage/Products/Testing-iphonesimulator/MyProject.app”
Any idea what's wrong here? I try to clean project - nothing.
In the Build Settings
in my target in Packaging
i change Product Bundle Identifier depends on configuration in my schema. It can have something to do with that, but not sure.
知道这里有什么问题吗?我尝试清理项目 - 没有。在Build Settings
我的目标中,Packaging
我更改了产品包标识符取决于我的架构中的配置。它可能与此有关,但不确定。
-- EDIT
- 编辑
Ok figure how to narrow the problem. When i change settings in scheme to use Build Configuration Debug
instead of Testing
seems to work, but I need separate configuration for testing.
确定如何缩小问题的范围。当我更改方案中的设置以使用构建配置Debug
而不是Testing
似乎工作时,但我需要单独的配置进行测试。
采纳答案by Jakub
Ok figure it out. There is a problem with naming packages. Unfortunatelly there is some issue with Xcode. I was using different Module Names for different Configurations. So go to Project
-> Build Settings
-> Product Module Name
Change name in all configurations for same name without spaces.
好的弄清楚。命名包有问题。不幸的是,Xcode 存在一些问题。我为不同的配置使用了不同的模块名称。因此,转到Project
-> Build Settings
->Product Module Name
在所有配置中更改名称以获取相同名称且不带空格。
回答by masty
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:
这最终修改了我的 xcodeproj 中的以下值:
- BUNDLE_LOADER = "$(TEST_HOST)";
- TEST_HOST = "$(BUILT_PRODUCTS_DIR)/myappname.app/myappname";
- BUNDLE_LOADER = "$(TEST_HOST)";
- TEST_HOST = "$(BUILT_PRODUCTS_DIR)/myappname.app/myappname";
回答by DenHeadless
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.
您可能还会遇到另一种情况。如果您需要主要目标的不同产品名称(例如 Debug、Staging、Production) - 并尝试使用 Xcode Host Application 选择器,它将向 TEST_HOST 构建设置写入不正确的值。
And while error message you see is about bundle identifier in Debug configuration, Xcode actually complains about TEST_HOST in Releaseconfiguration.
虽然您看到的错误消息是关于 Debug 配置中的包标识符,但 Xcode 实际上在Release配置中抱怨 TEST_HOST 。
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_HOSTshould be following:
我通过手动更改 TEST_HOST 构建设置来修复它。例如,如果您将主目标上的 ProductName 设置为 Debug 中的 AppDebug 和 Release 配置中的AppRelease,则您的TEST_HOST应如下所示:
What Xcode sets:
什么 Xcode 设置:
$(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
回答by mevdev
回答by JanBrinker
It seems there are several bugs in Xcode8 that can cause this. However I have found a solution for the case where Xcode tries to find the TEST_HOST app within the Intermediates/CodeCoverage/
folder. (I tried all other solutions with the module names etc and it didn't work for me.)
Xcode8 中似乎有几个错误可能导致这种情况。但是,对于 Xcode 尝试在Intermediates/CodeCoverage/
文件夹中查找 TEST_HOST 应用程序的情况,我找到了解决方案。(我使用模块名称等尝试了所有其他解决方案,但对我不起作用。)
The issue itself seems to be that Xcode does not even try to build the app before running the tests. Howeveronce Xcode is able to find the TEST_HOST in the folder it willrebuild when launching the tests. That's how we can find our way around it.
问题本身似乎是 Xcode 在运行测试之前甚至没有尝试构建应用程序。但是,一旦 Xcode 能够在文件夹中找到 TEST_HOST,它将在启动测试时重建。这就是我们如何找到解决方法的方法。
Two possible solutions:
两种可能的解决方案:
If you don't haveto have code coverage:Go to your unit test target's Build Settingsand set Enable Code Coverage Support
to Noanddeactivate code coverage in your build scheme's test setting. (Edit scheme, select Teston the left). If you want to run your unit tests and still get that TEST_HOST error message, try building (CMD+B) or running your app. Then you can run your tests without that error. Voilá.
如果你不具备有代码覆盖率:去你的单元测试目标的构建设置,并设置Enable Code Coverage Support
到没有和去激活代码覆盖率在构建计划的测试设置。(编辑方案,选择左侧的测试)。如果您想运行单元测试但仍然收到 TEST_HOST 错误消息,请尝试构建 ( CMD+ B) 或运行您的应用程序。然后您可以运行您的测试而不会出现该错误。瞧。
If you need code coverage:You can follow a certain workaround to get that Intermediates/CodeCoverage/..
folder filled. Once the app is inside Xcode will rebuild for the unit tests as it should, but you need to get it filled once. This is how you do it:
如果您需要代码覆盖率:您可以按照某种解决方法来Intermediates/CodeCoverage/..
填充该文件夹。一旦应用程序在 Xcode 中,它就会像它应该的那样为单元测试重建,但你需要让它填充一次。这是你如何做到的:
- In the app and the unit test target select Nofor "Enable Code Coverage Support"
- Then in the "General" tab of the unit test target set the test host application to "None"
- Uncheck "Allow testing Host API"
- Try to start unit tests. Xcode will now at least try to build. If Xcode gives a build error (sometimes Xcode complains about Cocoapods here in my experience), try building once again.
- Re-check "Allow testing Host API" again in the Unit Test target
- Try running the tests again as above. Xcode should complain.
- Now set the test host to the app.
- Now the tests should run through. (Until you run a clean, then you'll have to re-do these steps..)
- 在应用程序和单元测试目标中,为“启用代码覆盖支持”选择否
- 然后在单元测试目标的“常规”选项卡中将测试主机应用程序设置为“无”
- 取消选中“允许测试主机 API”
- 尝试开始单元测试。Xcode 现在至少会尝试构建。如果 Xcode 出现构建错误(根据我的经验,有时 Xcode 会在这里抱怨 Cocoapods),请再次尝试构建。
- 在单元测试目标中再次重新选中“允许测试主机 API”
- 尝试再次运行上述测试。Xcode 应该抱怨。
- 现在将测试主机设置为应用程序。
- 现在测试应该通过了。(直到您运行干净,然后您必须重新执行这些步骤..)
I know, it's bothersome. But it's the only solution to the problem so far.
我知道,这很麻烦。但这是目前唯一解决问题的方法。
回答by Nicolas Miari
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.).
我也有一个包含多个方案的项目,每个方案都使用单独的配置(Debug、AdHoc 等)和单独的产品名称(MyApp、MyApp_Dev、MyApp_Staging 等)构建应用程序。
Thankfully, they all have the same Module name so my unit test source files can simply use @testable import MyApp
, regardless of active scheme).
值得庆幸的是,它们都具有相同的模块名称,因此我的单元测试源文件可以简单地使用@testable import MyApp
,而不管活动方案如何)。
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:
为了克服这个错误,我只需要确保对于我想要测试的应用程序目标的每个方案,以下两个匹配:
- The App Target's Build Settings > Product Namefor that build configuration (.e.g, "Debug"),
- The Test Target's Build Settings > Test Hostfor the same build configuration (the part after
$(BUILT_PRODUCTS_DIR)...
)
- 该应用目标的构建设置>产品名称为构建配置(.eg,‘调试’),
- 相同构建配置的测试目标的构建设置 > 测试主机(之后的部分
$(BUILT_PRODUCTS_DIR)...
)
So, if #1 is (for example):
因此,如果 #1 是(例如):
MyApp-Debug
, then #2 must be:
,那么#2 必须是:
$(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 targetwas looking for a host named ending with a suffix of -STG (staging).
在我的例子中,我的方案是AdHoc
使用以-DEV
(development)后缀结尾的产品名称构建配置,但测试目标正在寻找一个以-STG(staging)后缀结尾的主机。
回答by Suryavel TR
Under Test Target >> Build Setting >> Testing >> Test Hostyou can see the .app file which should be used for testing.
在测试目标 >> 构建设置 >> 测试 >> 测试主机下,您可以看到应该用于测试的 .app 文件。
For me **.appfile name was wrong. And I replaced it with **/Build/Intermediates/CodeCoverage/Products/Debug-iphonesimulator/**.app(check for the .app file present under this directory).
对我来说**.app文件名是错误的。我将它替换为**/Build/Intermediates/CodeCoverage/Products/Debug-iphonesimulator/**.app(检查此目录下的 .app 文件)。
回答by JosephH
I ran into this error a lot and eventually discovered that it was caused by varying PRODUCT_NAME between Debug and Release build configurations.
我经常遇到这个错误,最终发现它是由 Debug 和 Release 构建配置之间的 PRODUCT_NAME 变化引起的。
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).
我们这样做是为了使 Debug 版本在安装在手机上时具有不同的应用程序名称(以及不同的 bundle id,因此我们可以将它们与 App Store 版本并排安装)。
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).
我们恢复了这一更改,并在构建配置中添加了一个新的 APP_DISPLAY_NAME 设置,在构建类型之间进行了改变,并将 Info.plist 更改为使用 $(APP_DISPLAY_NAME) 而不是 $(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.
这样做之后,进入项目中的测试目标并确保“常规”中的“主机应用程序”设置实际上已设置为您的应用程序非常重要。
回答by Христо Узунов
What I have discovered is that the tests will not run unless you have built and run the same target you are running the tests against on the device/sim you are testing on.
我发现,除非您在正在测试的设备/sim 上构建并运行了与运行测试相同的目标,否则测试将不会运行。
For example, if I run the tests against target Production, then I would have to build and run the target Production on the device/sim before I can run the tests. If I did not do that, it will give me the same error.
例如,如果我针对目标生产运行测试,那么我必须在设备/sim 上构建和运行目标生产,然后才能运行测试。如果我不这样做,它会给我同样的错误。
回答by vikas kumar jangir
go to xcode Preferences
-> location
> Derived Data Advance -> select build location Unique
转到 xcode Preferences
-> location
> 派生数据高级 -> 选择构建位置Unique