'XCTest/XCTest.h' file not found

I'm working on becoming a serious Xcode user. Figured on my newest project I should make a unit test to test the functionality of just a portion of my code. So I go through the steps to add a unit test case class, and the initial template triggers the error above. This seems pretty bizarre considering that (if I'm reading the documentation right) the XCTest framework is supposed to be a standard part of the SDK.


How does this happen? And how can I fix it, or at least work around it reasonably well?

Replies

I'm working on becoming a serious Xcode user.

Not too serious I hope (-:

This seems pretty bizarre considering that (if I'm reading the documentation right) the XCTest framework is supposed to be a standard part of the SDK.

Correct.

How does this happen?

I’m not sure. I regularly add unit test targets to existing projects and it works just fine.

To start:

  • What version of Xcode are you using?

  • What template did you use to create your original project? If you don’t remember the exact template that’s OK, I’m primarily interested in which OS you’re targeting.

  • If you create a new test project from scratch and check the Include Unit Tests box during the creation process, does that work?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Ohhhhh...


So I originally created my project using the "Command Line Tool" template for macOS, which doesn't have that Include Unit Tests option. Creating a Cocoa App from scratch gives me that option, and fortunately the Cocoa App recognizes <XCTest/XCTest.h> just fine. Added a line to the testExample method just to make sure, and ran the test, and it behaved just as expected.

I might as well get "serious" about picking up UI design while I'm at it (-:


Thanks for pointing me in the right direction!