SPM modules not found in test target

859 views Asked by At

I'm struggling with the SPM modules in the unit test target. Simply adding @testable import MyApp and then running UTs ends up with an error saying that an SPM module has not been found.

To be more explicit, those are the error lines:

/MyApp-cxdzdpxkuamerffyiosojkxpvujl/Build/Intermediates.noindex/MyApp.build/Debug-iphoneos/MyAppTests.build/Objects-normal/arm64/MyAppTests.swiftdoc: No such file or directory

/MyApp-cxdzdpxkuamerffyiosojkxpvujl/Build/Intermediates.noindex/MyApp.build/Debug-iphoneos/MyAppTests.build/Objects-normal/arm64/MyAppTests.abi.json: No such file or directory

/MyApp-cxdzdpxkuamerffyiosojkxpvujl/Build/Intermediates.noindex/MyApp.build/Debug-iphoneos/MyAppTests.build/Objects-normal/arm64/MyAppTests.swiftmodule: No such file or directory

/MyApp-cxdzdpxkuamerffyiosojkxpvujl/Build/Intermediates.noindex/MyApp.build/Debug-iphoneos/MyAppTests.build/Objects-normal/arm64/MyAppTests.swiftsourceinfo: No such file or directory

I've checked the folder and those files aren't indeed there.

What I've tried and more details:

  1. the only package I've added to the project is Firebase (9.6.0) and as I mentioned, it was added via SPM
  2. no Cocoapods or Carthage was ever used in this project, so I'm using just the xcodeproj file.
  3. Enable testability is set to true for Debug configuration in both targets (the main and the test)
  4. the scheme is set up to launch the tests with Debug conf
  5. the get the same results when I run the tests in a host app or not
  6. I've also tried to remove the test target and add it again, but no change
  7. Xcode 14.1 and M1 machine
1

There are 1 answers

0
Campbell_Souped On

I was able to resolve this issue on my unit test target by

  • creating a new project named MyApp
  • Navigate to the Unit Test target's build settings
  • search for TEST_HOST
  • You should see both Linking -> Bundle Loader and Testing -> Test Host sections

In your actual project, do the following:

  • set all the bundle loader Build Configurations (e.g., Debug / Release, etc) to $(TEST_HOST)
  • Set all the Test Host Build Configurations to $(BUILT_PRODUCTS_DIR)/MyApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/MyApp, replacing MyApp with your corresponding .app name

Test host settings after the change