XCTest/XCTest.h not found on old projects built in Xcode 6
IosXcodeCocoapodsXctestIos Problem Overview
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.
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 new project with Xcode 6 it appears the library is linked in automatically.
Perhaps of some relevency, my XCTest-needing dependencies are all brought in via Cocoapods.
Is there anything I'm unaware of that I need to update with my project?
Ios Solutions
Solution 1 - Ios
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).
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.
Solution 2 - Ios
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.
Solution 3 - Ios
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.
Solution 4 - Ios
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.
Solution 5 - Ios
@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
Solution 6 - Ios
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...https://stackoverflow.com/questions/19230002/import-xctest-in-to-existing-project
Solution 7 - Ios
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
.
Solution 8 - Ios
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.
Solution 9 - Ios
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
Solution 10 - Ios
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; };
Solution 11 - Ios
Re-visiting my very old question, as of Xcode 11 you can set
ENABLE_TESTING_SEARCH_PATHS = YES
in your target