Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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


I get this error if I create a macOS dynamic framework target, which links to XCTest.framework (the target is a framework target, not a testing target!).

In this case the problem is solved by adding

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks

to project's "Build Settings / Framework Search Paths".


After lots of troubleshooting and bouncing around Stack Overflow pages such as this one, I managed to find one detail that was not mentioned on the other iOS Unit Test troubleshooting pages.

If your project uses CocoaPods, make sure to include your test target nested inside your main application's target. Your podfile might not include it if you created your test target after running pod init. Your podfile should look something like this:

target 'YourApp' do
    target 'YourAppTests' do
        inherit! :search_paths
        # Pods for testing
    end
end

Remember to save your podfile and run pod install after doing so.

Hope it helps!