XCTest/XCTest.h 在 Xcode 6中构建的旧项目中没有找到

我有一些项目,我试图建立与 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>

我注意到 XCTest.Framework 不再在“具有二进制文件的链接库”构建阶段列表中,但这没有关系,因为当我使用 Xcode 6创建一个 新的项目时,看起来这个库是自动链接的。

也许有一些相关性,我的 XCTest 需要依赖都是通过 Cocoapods 带来的。

有没有什么我不知道的地方需要更新我的项目?

75126 次浏览

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.

Note: This may not be needed for any projects created in Xcode 7.

CocoaPods had a fix for this here and 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).

$(PLATFORM_DIR)/Developer/Library/Frameworks

screenshot

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.

It is not detrimental to earlier versions of Xcode so should be safe to use.

@squarefrog has the right answer but you'll have to keep doing that manually each time you update your pods :(

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:

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

I have faced same issue after some time I have imported XCTest framework from build phases and solved the issue.

Build phases-> XCTest.Framework>clean and run. I hope it will be helpful to some one..

for your reference...Import XCTest in to existing project

As of the time of writing, the latest version of Cocoapods (0.33.1) doesn't have a fix for the problem.

But the cutting edge version does.

Follow this guide to 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.

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.

This is the easiest work-around I've found. No project changes are necessary. And this change will persist until your next Xcode upgrade:

cd /Applications/Xcode6-Beta7.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/Developer/Library/Frameworks
ln -s ../../../../../Library/Frameworks/XCTest.framework

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.

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; };

I was moving files in a project around. All you have to do is select your test files xxxTests.m etc. and in file inspector select target as test and not as a regular target.

The best way to have an XCTest is to add it from the Test Navigator (5th icon in the left pane).

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)

  • 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.

Re-visiting my very old question, as of Xcode 11 you can set

ENABLE_TESTING_SEARCH_PATHS = YES

in your target