ios 在 Xcode 6 中构建的旧项目中找不到 XCTest/XCTest.h
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24275470/
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
XCTest/XCTest.h not found on old projects built in Xcode 6
提问by Erik Kerber
I have a few projects I'm trying to build with Xcode 6 Beta 2. The projects all have some type of library that uses XCTest (Kiwi/XCTest and Specta) that don't build in Xcode 6 because XCTest/XCTest.h cannot be found.
我有几个项目正在尝试使用 Xcode 6 Beta 2 构建。这些项目都有一些使用 XCTest(Kiwi/XCTest 和 Specta)的库,这些库不在 Xcode 6 中构建,因为 XCTest/XCTest.h 不能被发现。
fatal error: 'XCTest/XCTest.h' file not found
#import <XCTest/XCTest.h>
I noticed that XCTest.framework is no longer in the "Link Libraries with Binaries" build phase list, but that's fine because when I create a newproject with Xcode 6 it appears the library is linked in automatically.
我注意到 XCTest.framework 不再在“Link Libraries with Binaries”构建阶段列表中,但这很好,因为当我使用 Xcode 6创建一个新项目时,它似乎自动链接了该库。
Perhaps of some relevency, my XCTest-needing dependencies are all brought in via Cocoapods.
也许有一些相关性,我需要 XCTest 的依赖项都是通过 Cocoapods 引入的。
Is there anything I'm unaware of that I need to update with my project?
有什么我不知道的,我需要更新我的项目吗?
回答by squarefrog
Note:This may not be needed for any projects created in Xcode 7.
注意:对于在 Xcode 7 中创建的任何项目,这可能不需要。
CocoaPods had a fix for this hereand here
In order to fix this for any CocoaPod dependencies you need to add the following to FRAMEWORK_SEARCH_PATHS
in any Pod target that requires XCTest (e.g. Kiwi, Specta, FBSnapshotTestCase, etc).
为了针对任何 CocoaPod 依赖项修复此问题,您需要FRAMEWORK_SEARCH_PATHS
在任何需要 XCTest 的 Pod 目标(例如 Kiwi、Specta、FBSnapshotTestCase 等)中添加以下内容。
$(PLATFORM_DIR)/Developer/Library/Frameworks
$(PLATFORM_DIR)/Developer/Library/Frameworks
This will allow you to reference XCTest in any dependencies you may have. This may be fixed in a future update of CocoaPods, or the Pod you are referencing, so you may want to remove it later.
这将允许您在您可能拥有的任何依赖项中引用 XCTest。这可能会在 CocoaPods 或您正在引用的 Pod 的未来更新中修复,因此您可能希望稍后将其删除。
It is not detrimental to earlier versions of Xcode so should be safe to use.
它不会对早期版本的 Xcode 有害,因此应该可以安全使用。
回答by Jakub Truhlá?
I was moving files in a project around. All you have to dois select your test files xxxTests.m
etc. and in file inspector
select target
as test
and not as a regular target.
我正在一个项目中移动文件。您所要做的就是选择您的测试文件xxxTests.m
等,并file inspector
选择target
作为test
而不是常规目标。
回答by Mustafa
I've noticed that XCTest is available to a test target only (in Xcode 6). If you are using using XCTest for any other target (for whatever reason), you will see the XCTest.h not found
error.
我注意到 XCTest 仅可用于测试目标(在 Xcode 6 中)。如果您将 XCTest 用于任何其他目标(无论出于何种原因),您将看到XCTest.h not found
错误。
回答by deanWombourne
@squarefrog has the right answerbut you'll have to keep doing that manually each time you update your pods :(
@squarefrog 有正确的答案,但每次更新 Pod 时,您都必须手动执行此操作:(
If you add this to your podfile it will automatically add the extra path for you. E.g. if you wanted to add $(PLATFORM_DIR)/Developer/Library/Frameworks
to FRAMEWORK_SEARCH_PATHS
for Specta:
如果你把它添加到你的 podfile 中,它会自动为你添加额外的路径。例如,如果你想添加$(PLATFORM_DIR)/Developer/Library/Frameworks
到FRAMEWORK_SEARCH_PATHS
为Specta:
post_install do |installer|
target = installer.project.targets.find { |t| t.to_s == "Pods-Tests-Specta" }
if (target)
target.build_configurations.each do |config|
s = config.build_settings['FRAMEWORK_SEARCH_PATHS']
s = [ '$(inherited)' ] if s == nil;
s.push('$(PLATFORM_DIR)/Developer/Library/Frameworks')
config.build_settings['FRAMEWORK_SEARCH_PATHS'] = s
end
else
puts "WARNING: Pods-Tests-Specta target not found"
end
end
回答by Tash Pemhiwa
This error comes up when you have added a file where XCTest is being used outside of a test target. To fix this in AppCode, you can right click on any suspected file and select 'Manage Targets' then make sure only the test target is checked.
当您添加了在测试目标之外使用 XCTest 的文件时,会出现此错误。要在 AppCode 中解决此问题,您可以右键单击任何可疑文件并选择“管理目标”,然后确保仅选中测试目标。
回答by Narasimha Nallamsetty
I have faced same issue after some time I have imported XCTest framework from build phases and solved the issue.
我从构建阶段导入 XCTest 框架并解决了这个问题一段时间后,我遇到了同样的问题。
Build phases-> XCTest.Framework>clean and run. I hope it will be helpful to some one..
构建阶段-> XCTest.Framework>清理并运行。我希望它会对某人有所帮助..
for your reference...Import XCTest in to existing project
供您参考...将XCTest 导入到现有项目中
回答by fatuhoku
As of the time of writing, the latest version of Cocoapods (0.33.1) doesn't have a fix for the problem.
在撰写本文时,最新版本的 Cocoapods (0.33.1) 还没有修复该问题。
But the cutting edge version does.
但尖端版本确实如此。
Follow this guideto set the latest version of Cocoapods up from source. I call mine pod-dev
(covered in the guide) to distinguish it from the gem-installed version of pods.
按照本指南从源代码设置最新版本的 Cocoapods。我称它为我的pod-dev
(在指南中介绍)以将其与安装了 gem 的 pod 版本区分开来。
The benefit of this approach is that you don't need extra scripting in your Podfile. You just have to remember to do a pod-dev install
instead of the usual pod install
.
这种方法的好处是您不需要在 Podfile 中编写额外的脚本。你只需要记住做一个pod-dev install
而不是通常的pod install
。
回答by tontonCD
The best way to have an XCTest is to add it from the Test Nagigator (5th icon in the left pane).
拥有 XCTest 的最佳方法是从 Test Nagigator(左窗格中的第 5 个图标)添加它。
Acting so, the new xx.m test file doesn't target (in the right pane) an app (in the left pane > Target, Wrapper Extension : app), but a bundle (Wrapper Extension: xctest)
这样做,新的 xx.m 测试文件不针对(在右窗格中)应用程序(在左窗格中 > 目标,包装扩展:app),而是一个包(包装扩展:xctest)
- the XCTest.framework remains in Red,
- because of some modifications you can have the error
'XCTest/XCTest.h' file not found
, it's because your file had got to target an app.
- XCTest.framework 保持红色,
- 由于一些修改,您可能会遇到错误
'XCTest/XCTest.h' file not found
,这是因为您的文件必须针对应用程序。
回答by Steven Kramer
This is the easiest work-around I've found. No project changes are necessary. And this change will persist until your next Xcode upgrade:
这是我找到的最简单的解决方法。无需更改项目。并且此更改将持续到您的下一次 Xcode 升级:
cd /Applications/Xcode6-Beta7.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/Developer/Library/Frameworks
ln -s ../../../../../Library/Frameworks/XCTest.framework
回答by AnneTheAgile
On a project without Cocoapods (so not directly answering the OP's question but perhaps helpful for me or others in the future), we had the same issue. It was solved by replacing our previous OCTest items with XCTest. For example, a file MyApp.xcodeproj/project.pbxproj has this diff (shortened) ;
- path = MyAppUnitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
+ path = MyAppUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
在没有 Cocoapods 的项目中(因此不直接回答 OP 的问题,但可能对我或将来的其他人有帮助),我们遇到了同样的问题。通过用 XCTest 替换我们之前的 OCTest 项目解决了这个问题。例如,文件 MyApp.xcodeproj/project.pbxproj 有这个差异(缩短);
- path = MyAppUnitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
+ path = MyAppUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };