After renaming project i get <XCTest/XCTest.h> not found. After renaming project i get <XCTest/XCTest.h> not found. xcode xcode

After renaming project i get <XCTest/XCTest.h> not found.


I came across something similar and I'm wondering if my solution might be helpful.

You may want to check that the file which is throwing the error is included in the appropriate Target Source's "Compile Sources". It's possible your file might not have been included. In my case it had been included with the project target and not with the test target. Since XCTest is only accessible with the Test Target, it wouldn't compile for me generating the error "XCTest/XCTest.h file not found".

Project Targets >> Build Phases >> Compile Sources:Making sure your test file is added as a compile source for the test target.

You can fix this by either manually adding it to the "Compile Sources" as per the above image or you can remove the file from the project and re-add it, making sure to select the Test Target when you re-add:Adding a new file to the Test Target.

In case it helps anyone else I came across this after moving a test case file (in the file system) and then re-adding it to my test project (right click, 'Add Files to "Project"...'). It turns out I wasn't adding the file to the Test target - I was just adding it to the Project Target.


Xcode 7.2.1/Swift 2.1.1:

When I created a new File, I chose iOS>Source>Swift File, and even though I checked the Test target, I still got an error on the import XCTest line:

error: cannot load underlying module for 'XCTest'

To get rid of that error, when I created a new file I had to choose iOS>Source>Unit Test Case Class, and I accepted the defaults for everything else.