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.
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:
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With