Include an Xcode 7 UI testing dependency via Cocoapods?
Asked Answered
P

3

12

I have an existing Objective-C project and I want to add a new Xcode 7 UI testing target with OHHTTPStubs as a dependency.

I added the new (Swift 2.0) UI testing target in Xcode, then added this to my Podfile:

target 'FooUITests' do
    pod 'OHHTTPStubs', '4.0.1'
end

I ran pod update, cleaned, and rebuilt. But when I try and import OHHTTPStubs at the top of the template UI test .swift file Xcode created for me, it complains "No such module 'OHHTTPStubs'".

I'm using Cocoapods version 0.37.2—is importing an Objective-C dependency into a Swift (... UI test) target even meant to work?

UPDATE: As noted in my self-answer below, adding use_frameworks! to my Podfile gets me clean compilation—I can import OHHTTPStubs at the top of my test file, reference classes and methods, code completion works—but when I actually go to run the tests I get the following output in the Xcode console:

2015-06-18 10:06:57.134 XCTRunner[51557:609693] The bundle “FooUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2015-06-18 10:06:57.135 XCTRunner[51557:609693] (dlopen_preflight(/Users/foo/Library/Developer/CoreSimulator/Devices/38181A1B-67B1-4D7F-B434-85361533F985/data/Containers/Bundle/Application/83C68748-55A3-4A02-8862-C18ADEF895B5/FooUITests-Runner.app/PlugIns/FooUITests.xctest/FooUITests): Library not loaded: @rpath/OHHTTPStubs.framework/OHHTTPStubs
  Referenced from: /Users/foo/Library/Developer/CoreSimulator/Devices/38181A1B-67B1-4D7F-B434-85361533F985/data/Containers/Bundle/Application/83C68748-55A3-4A02-8862-C18ADEF895B5/FooUITests-Runner.app/PlugIns/FooUITests.xctest/FooUITests
  Reason: image not found)

There do seem to be Release-iphoneos and Release-iphonesimulator builds of the OHHTTPStubs.framework under my ~/Library/Developer/DerivedData directory though.

Any hints as to what is going on?

Pi answered 17/6, 2015 at 13:48 Comment(0)
P
2

Turns out all I needed to do was tell Cocoapods to use_frameworks! (for the Swift target only) in the Podfile:

target 'FooUITests' do
  use_frameworks!
  pod 'OHHTTPStubs', '4.0.1'
end
Pi answered 17/6, 2015 at 13:57 Comment(2)
Hmm, maybe not so fast. It's not working anymore, despite (because of?) many cleanings and rebuildings. Now I'm getting "The bundle “Foo” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle." whenever I try and actually run the tests, though it does build.Pi
Did you ever figure this out? Having the same issues.Altricial
E
1

Adding a [CP] Embed Pods Frameworks Run Script build phase to my test target fixed this for me, as described in this CocoaPods GitHub issue.

Note that in your regular target, your Build Phases section contains both [CP] Copy Pods Resources (which runs "${SRCROOT}/../../Pods/Target Support Files/Pods-YOURTARGET/Pods-YOURTARGET-resources.sh"), and [CP] Embed Pods Frameworks (which runs "${SRCROOT}/../../Pods/Target Support Files/Pods-YOURTARGET/Pods-YOURTARGET-frameworks.sh"). But your test target contains only [CP] Copy Pods Resources.

Manually add the [CP] Embed Pods Frameworks Run Script phase to your test target (to run "${SRCROOT}/../../Pods/Target Support Files/Pods-YOURTESTTARGET/Pods-YOURTESTTARGET-resources.sh").

Embrangle answered 1/9, 2016 at 16:38 Comment(0)
K
0

Seems to work using CocoaPods 0.38.0.beta.2, check https://github.com/CocoaPods/CocoaPods/issues/3709

Krenek answered 8/7, 2015 at 0:44 Comment(1)
Not for me. I'm seeing the same issues on 0.39.Olav

© 2022 - 2024 — McMap. All rights reserved.