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

user3294722 picture user3294722 · Dec 5, 2014 · Viewed 12.5k times · Source

I first duplicated my project before I renamed it. After the rename i'm getting

Lexical or Preprocessor Issue <XCTest/XCTest.h> not found. 

The error directs me to the myapptests.m file which calls to

#import <XCTest/XCTest.h>

Also the next line

@interface SpyShotTests : XCTestCase

The "XCTestCase" is not hi-lighted in purple.

Any tutorial i've seen has directed me to the Framework Search Paths in Build Settings - but the framework search path is exactly the same as the initial file and that file builds with no issues.

Answer

Derek Lee picture Derek Lee · Dec 14, 2014

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.