14

Every time I start to run my app, or I'm just starting Xcode I get this error:

This is the error.

I think the problem is that I don't know where my .xctest files are. I think I maybe deleted them.

Would be very nice if someone of you could help me! Maybe tell me how to recover these files, make some new one or something else.

3 Answers 3

49

You accidentally added one of your Xcode Unit Test files to your main app target.

Remove it:

  1. Select test file
  2. Open right side panel
  3. Select Identity and Type tab
  4. Unselect your app Target (not the unit test lego icon)

Tip: Next time you add a new unit test, only add it to your unit test target. If you accidentally include any of your app targets, they will not have the XCTest framework available.

Fix Cannot load underlying module for 'XCTest'

1

See also Apple Technical Q&A QA1954 'Cannot load underlying module for XCTest' which covers several variants of the issue

https://developer.apple.com/library/archive/qa/qa1954/_index.html

0

The main project does not link with the XCUnit framework. You should create a separate testing target for your project, if one does not already exist, and add your test source files to that target.

Select your project in the Project Navigator. This will open the project's settings in the editor. Click the "+" button at the bottom of the column listing your Targets. If you are working on an iOS project template, select iOS > Test > iOS Unit Testing Bundle.

If you are working on an OS X project template, select OS X > Test > OS X Unit Testing Bundle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.