Trouble importing XCTest.h in Xcode 12

I'm getting the following compiler error when trying to build my unit tests in Xcode 12:


Did not find header ‘XCTest.h’ in framework ‘XCTest’ (loaded from ‘/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/Developer/Library/Frameworks’)

on a line that looks like this:

Code Block objective-c
#import <XCTest/XCTest.h>


When trying:

Code Block objective-c
@import XCTest;


I get:

Could not build module ‘XCTest’


This works fine in Xcode 11.x

I am unsure what other information may be relevant to provide here.



Hi Cameron2019, it would be helpful if you could provide more of the build log so we have more information to use to try to understand the issue.

Have you used xcode-select to switch your main developer tools location to the beta?
Thank you! Yes, I am properly xcode-select'd and am pointing at the beta. The full failure from the build log is posted below, let me know if I can post anything else!

The project uses the open source Quick and Nimble testing frameworks (via CocoaPods) and I think that may be related. Specifically, it does this 'FRAMEWORK_SEARCH_PATHS' => '$(PLATFORM_DIR)/Developer/Library/Frameworks'. From some playing around I've done, removing this seems to help, but there's not a great way to actually do that permanently.



I had the same problem, and found a workaround. This appeared in the build log:

note: did not find header 'XCTest.h' in framework 'XCTest' (loaded from '/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/Developer/Library/Frameworks')

Sure enough, the XCTest.framework in that path was missing a Headers directory. Either they forgot to copy it in, or they're linking against the incorrect framework.

I was able to fix the problem by adding a symbolic link to the current Xcode's XCTest's Headers directory:

cd /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/Developer/Library/Frameworks/XCTest.framework ln -s /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks/XCTest.framework/Headers

(If your Xcode installations aren't in /Applications, don't forget to change the top of those paths appropriately for your installation.)

Once I did that, then my project built correctly.


TungstenT's response is the way I'd recommend fixing this issue. Third-party frameworks may not always update their search paths to be compatible with Beta install locations. I also suspect that you could solve this issue without changing the search paths by renaming your Xcode Beta to Xcode.app
Test bundle targets in Xcode automatically have the relevant search path build settings configured so that they can import XCTest.framework. But libraries and frameworks which need to import XCTest require these search paths to be set manually.

In Xcode 11.4 and later, you can configure this easily using just one build setting:
Code Block
ENABLE_TESTING_SEARCH_PATHS = YES

Also known as the "Enable Testing Search Paths" setting in the Xcode project editor's Build Settings tab. This automatically configures all of the necessary search paths for non-test bundle targets in Xcode. I recommend adopting this setting for testing frameworks.
In regards to ENABLE_TESTING_SEARCH_PATHS, my test targets have this enabled, and I've gone ahead with some post_install hooks in my Podfile to enable this in the Debug configuration for all of my pods as well.

With this, I still get the original error.

I then additionally modified all the pod-generated xcconfig files to remove all instances of FRAMEWORK_SEARCH_PATHS = $(PLATFORM_DIR)/Developer/Library/Frameworks.

With both of these fixes (?) in place, I get a new error: cannot specify -o when generating multiple output files

I could take the symbolic linking approach as suggested by TungstenT but that feels like it's papering over a deeper issue.
I've been seeing the same issue in our project. I put together a sample project which reproduces the issue on Xcode 12 beta 1 here: https://github.com/noahsark769/NGXCTestNotFoundExample - I've also filed it as FB7775577

Having same issues as everyone before. None of the fixes listed here have helped me thus far. Do we wait for Beta 3 or is there another fix we aren't seeing?
Forcing the ENABLETESTINGSEARCH_PATHS = YES to my dependencies (Kiwi) seems to make them compile, but then the test target fails. Even with that setting turned on in the app and test targets.

 note: did not find header 'XCTest.h' in framework 'XCTest' (loaded from '/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/Developer/Library/Frameworks')

Seems like it's because some libraries still use the old style of import "#import <XCTest/XCTest.h>".

I'm not sure anything can be done to fix that.
Hi @Cameron2019,

Have you been able to solve this issue? It's still present in Xcode 12 Beta 3.

Thanks!




You can create a symbolic link as follows

$cd ~/Downloads/Xcode\ 12/Xcode-beta\ 3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Developer/Library/Frameworks
$mv XCTest.framework XCTest.framework.old
$ln -s ../../../../../Library/Frameworks/XCTest.framework .


I'm seeing this problem in Xcode 12 Beta 3. This is ridiculous. We don't ship code unless the tests pass. How does Apple expect us to build reliable apps and ship them when we are a month out from iOS 14 dropping and we can't even run our test suites. I've tried all of the ideas in this thread and nothing works. Does anyone have anything new they have tried or is there something missing?

I ran into some troubles like this today. The build would work, but the side builds it does to find errors as you are typing were failing and spewing lots of errors that all start with XCTest/XCTest.h not found. (Xcode 15.3). I added /Library/Frameworks (recursive) to the project's framework search path and the issue went away.

Trouble importing XCTest.h in Xcode 12
 
 
Q