Cannot load underlying module for XCTest Cannot load underlying module for XCTest xcode xcode

Cannot load underlying module for XCTest


Double check that the file in question is not in the main target but instead only the test target. Only the test target will have that framework to import.


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.

  1. Select your project in the Project Navigator. This will open the project's settings in the editor.
  2. Click the "+" button at the bottom of the column listing your Targets.

enter image description here

  1. 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.


You've just added your tests file/class into main target and not into test target by mistake. Simple as that.

Solution:

1) Remove test file from "Compile Sources" list on "Build Phases" tab for main target

2) Add same file into "Compile Sources" on "Build Phases" tab for test target

It must resolve the issue