Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 655
user3294722 Avatar asked Dec 05 '14 21:12

user3294722


2 Answers

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.

like image 198
Derek Lee Avatar answered Nov 17 '22 21:11

Derek Lee


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.

like image 44
7stud Avatar answered Nov 17 '22 22:11

7stud