Search code examples
swiftxcodexctest

Cannot load underlying module for XCTest


I'm working in swift on Xcode and by default it creates a test file that references XCTest.

When I set the target membership to my main project it causes this error

Cannot load underlying module for XCTest

If this target membership is not set the tests runs properly and everything works fine.


Solution

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