Cannot load underlying module for XCTest

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'


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