Reputation: 886
I'm using Swift Package Manager on an iOS app on Xcode 11 following the instructions from https://developer.apple.com/videos/play/wwdc2019/408/
Everything looks great, except Unit Tests won't work now.
Upvotes: 39
Views: 12694
Reputation: 1372
Before you try the above, quit Xcode, and delete your derived data folder (~/Library/Developer/Xcode/DerivedData). If you're using cocoapods, run pod install
, and then re-open Xcode. This fixed the problem for me.
Upvotes: 0
Reputation: 2433
I was facing a similar issue in Xcode 14.1. Getting error Missing required module 'RxCocoaRuntime'
.
My fix was:
Upvotes: 12
Reputation: 7678
This appears to occur because SPM dependencies might not automatically be linked to test targets.
We can manually link it by:
Headlines
)HeadlinesTests
)Build Phases
in the top bar.Link Binary With Libraries
phase, add the required library from the SPM dependency (this looks like a white building within the SPM package 📦).Dependencies
phase.Upvotes: 76
Reputation: 4116
I saw this in Xcode 13 after I created a multi-platform app & had checked the box to create tests. The issue seems to be that Xcode created UI tests rather than unit tests as I had expected. I just made a new unit test target and everything worked as expected when importing my app in the test file.
Upvotes: 0
Reputation: 886
After researching a bit, I got this fixed by adding -Xcc -fmodule-map-file=$(PROJECT_TEMP_ROOT)/GeneratedModuleMaps/macosx/<missing module name>.modulemap
to OTHER_SWIFT_FLAGS
in the test target.
Source:
PS: Use -Xcc -fmodule-map-file=$(PROJECT_TEMP_ROOT)/GeneratedModuleMaps/iphonesimulator/<module name>.modulemap
if your platform is iOS.
UPDATE: Also, it seems that this is fixed on Xcode 11.2 beta2
Upvotes: 4