Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KIF test bundle XCTest.dylib not loading when using Swift

I'm trying to add new tests in Swift to an existing KIF test bundle currently written in Objective C.

Set up:

  • Xcode 6.4
  • cocoapods 0.37.2
  • Podfile uses latest version of KIF

I've set up the Swift bridging header, importing KIF and the other relevant parts of my project to make these available to Swift.

I've reduced things down to a simple test case, which doesn't even use KIF at this stage:

import Foundation

class MyFirstTest : KIFTestCase {

    func testOne() {
        NSLog("Done")
    }
}

The test bundle builds fine, but when I run I get:

2015-07-03 14:52:32.620 MyApp[1104:204793] Error loading /private/var/mobile/Containers/Data/Application/F20A664E-BD2D-4299-A93F-4C6758CBAF34/tmp/MyApp_UI_Tests.xctest/MyApp_UI_Tests: dlopen(/private/var/mobile/Containers/Data/Application/F20A664E-BD2D-4299-A93F-4C6758CBAF34/tmp/MyApp_UI_Tests.xctest/MyApp_UI_Tests, 262): Library not loaded: @rpath/libswiftXCTest.dylib

Referenced from: /private/var/mobile/Containers/Data/Application/F20A664E-BD2D-4299-A93F-4C6758CBAF34/tmp/MyApp_UI_Tests.xctest/MyApp_UI_Tests

Reason: image not found DevToolsBundleInjection: Error loading bundle '/private/var/mobile/Containers/Data/Application/F20A664E-BD2D-4299-A93F-4C6758CBAF34/tmp/MyApp_UI_Tests.xctest'

I have tried the suggestions here, including:

  • Setting run path search paths to @executable_path/Frameworks for both the App and the test bundle target
  • Setting "Embedded Content Contains Swift Code" to YES

I've also tried:

  • Full cocoapods clean and rebuild of project/workspace
  • Deleting all DerivedData and running a clean build

I've also seen suggestions that this could be related to the code signing identity, but the bundle fails to load on the simulator with the dev identity as well as on a real device.

If I revert back to only using Objective C tests, everything works fine.

What have I missed?

like image 251
John Martin Avatar asked Dec 25 '22 17:12

John Martin


1 Answers

Finally figured it out. For me, the solution was to make sure the runpath setting for the test bundle target included @loader_path/Frameworks as well as @executable_path/Frameworks.

As soon as I added that, everything loaded fine.

enter image description here

like image 143
John Martin Avatar answered Dec 28 '22 08:12

John Martin