Search code examples
iosxcoderealmcocoapodsxctest

The test runner failed to load the test bundle


I'm developing a cocoa touch framework and I'm importing "RealmSwift" using CocoaPods. The project builds successfully but the tests fails to load. I'm getting the following error:

xctest (97035) encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted. (Underlying error: The test runner failed to load the test bundle. Executable cannot be loaded for some other reason, such as a problem with a library it depends on or a code signature/entitlements mismatch.))

Crash log:

2019-02-27 17:35:44.197599+0400 xctest[12408:121075] The bundle “MyFrameworkTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2019-02-27 17:35:44.197835+0400 xctest[12408:121075] (dlopen_preflight(/Users/zakaria/Library/Developer/Xcode/DerivedData/MyFramework-cltpexonmtkefveximwygxbkkcrj/Build/Products/Debug-iphonesimulator/MyFrameworkTests.xctest/MyFrameworkTests): Library not loaded: @rpath/Realm.framework/Realm
  Referenced from: /Users/zakaria/Library/Developer/Xcode/DerivedData/MyFramework-cltpexonmtkefveximwygxbkkcrj/Build/Products/Debug-iphonesimulator/MyFrameworkTests.xctest/MyFrameworkTests
  Reason: image not found)

I tried every solution I could find online, but to no avail.

It's worth mentioning that this works successfully in a iOS project, the problem occurs only in a cocoa touch framework.

My podfile is as follow:

target 'Framework' do
  use_frameworks!

  pod 'RealmSwift', '~> 3.13.1'

  target 'FrameworkTests' do
    inherit! :search_paths
  end

end

I'm using Xcode version: 10.1 and CocoaPods version: 1.6.0


Solution

  • This is the podfile that worked for me:

    platform :ios, '11.0'
    
    def shared
      use_frameworks!
      pod 'RealmSwift', '~> 3.18.0'
    end
    
    target 'Framework' do
      shared
    end
    
    target 'FrameworkTests' do
      shared
    end