Cocoapods: 1.0.0.beta.6 with XCode 7.3 UI Test issue

Created on 1 Apr 2016  Ā·  22Comments  Ā·  Source: CocoaPods/CocoaPods

I'm using cocoapods version 1.0.0.beta.6. Have App with four targets:

  1. Target - main target with deployment target 8.0
  2. TargetTests - target for unit tests (Host application: Target)
  3. TargetUI - a copy of Target just to separate unit tests from UI tests, with deployment target 9.0
  4. TargetUITests - target for UI tests (Host application: TargetUI)

With Podfile:

source 'https://github.com/CocoaPods/Specs.git'

use_frameworks!
inhibit_all_warnings!

def common_pods
    pod 'XX1'
    pod 'XX2'
    pod 'XX3'
end

target 'Target' do
    platform :ios, '8.0'
    common_pods
end

target 'TargetUI' do
    platform :ios, '9.0'
    common_pods
    pod 'XX4'
    pod 'XX5'
end

Where:

XX5 - pods for UI test purposes with XCTest import within, require iOS 9+
XX4 - pods for UI test purposes require iOS 9+
XX3..XX1 - standard pods

All targets build with success. Unit tests works correctly. The problem appears when UI Testing:

Error:

dyld: Library not loaded: @rpath/XCTest.framework/XCTest
Referenced from: /Users/.../Frameworks/XX5.framework/XX5
Reason: image not found

What I've found so far is XCTests should not be imported beyond Tests. So I've changed the Podfile to separate XX5 pod with XCTest import to separate target:

With Podfile:

source 'https://github.com/CocoaPods/Specs.git'

use_frameworks!
inhibit_all_warnings!

def common_pods
    pod 'XX1'
    pod 'XX2'
    pod 'XX3'
end

target 'Target' do
    platform :ios, '8.0'
    common_pods
end

target 'TargetUI' do
    platform :ios, '9.0'
    common_pods
    pod 'XX4'
end


target 'TargetUITests' do
    platform :ios, '9.0'    
    pod 'XX5'
end

All targets build with success. Unit tests works correctly. The problem appears when UI Testing:

Error:

Test target TargetUITests encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted)

Summary:

UI Tests works ONLY when target 'TargetUITests' is not defined separately with pods. Empty 'TargetUITests' makes it working!

Most helpful comment

@neonichu This is still a problem with UITest targets. The "Embed Pods Frameworks" doesn't get included in the build phases. If I put it in manually, it works. Any idea where this left off on? This should be reopened as it's still affecting 1.0.0.rc.1

All 22 comments

It looks to me like this is a duplicate of https://github.com/CocoaPods/CocoaPods/issues/4944 ?

Not for me.
In the first code snippet I just showed that XCTests should not be imported beyond Tests target, that's all.

The real problem is described in the second part of my post (the second code snippet), that if I do it right (import pod with XCTests as a separate target) I cannot run UI Tests at all. All targets can compile, but UI Tests cannot run due to error "Test target TargetUITests encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted)"

In that case, could you share a project we could use to debug? Thanks!

This _ought_ to be fixed on master now

unfortunately it's not, just checked on beta 7...

This is a problem on 0.39.0, and after upgrading to 1.0.0-beta8, it's still a problem. The Embed Pods Frameworks build phase isn't being added to the UITests target, so that might be a symptom of the problem. Adding the run script doesn't seem to help.

Here's my current Podfile:

source 'https://github.com/CocoaPods/Specs'

platform :ios, '8.0'

use_frameworks!

def all_pods
    pod 'Intrepid', '~> 0.3.0'
    pod 'Intrepid/Rx', '~> 0.3.0'
    pod 'Crashlytics', '3.6.0'
    pod 'M13BadgeView', '1.0.4'
    pod 'Swifternalization', '1.3.1'
    pod 'RxSwift', '~> 2.0'
    pod 'RxCocoa', '~> 2.0'
    pod 'Genome', '~> 2.0'

    # TODO: Add specifiers for version. Analytics
    pod 'Analytics/Segmentio'
end

target 'application-name-ios' do #name changed for client discretion
    all_pods
end

target 'UnitTests' do
    all_pods
end

target 'UITests' do
    all_pods
end

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['ENABLE_BITCODE'] = 'NO'
            if "#{config}" == "Debug"
                config.build_settings['ENABLE_TESTABILITY'] = 'YES'
            end
        end
    end
end

The podfile is a bit weird right now, I've been trying everything I could think of for the last 2 days with no luck.

I notice that in the UITests target, the Embed Pods Frameworks phase isn't being added. Not sure if that will help diagnose.

I'm facing the same issue and already tried the latest CocoaPods 1.0.0.beta.8.
I'm using Xcode 7.3 (7D175).
I created an example repo to help with reproducing the problem.
After doing pod install I try to run the UI tests and building succeeds but then it fails.

Error message is:

The bundle ā€œuitestproblemUITestsā€ couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
(dlopen_preflight(/Users/mdio/Library/Developer/Xcode/DerivedData/uitestproblem-fzrkhrsghdyoseaobekimnrhrhpl/Build/Products/Debug-iphonesimulator/uitestproblemUITests-Runner.app/PlugIns/uitestproblemUITests.xctest/uitestproblemUITests): Library not loaded: @rpath/Alamofire.framework/Alamofire
  Referenced from: /Users/mdio/Library/Developer/Xcode/DerivedData/uitestproblem-fzrkhrsghdyoseaobekimnrhrhpl/Build/Products/Debug-iphonesimulator/uitestproblemUITests-Runner.app/PlugIns/uitestproblemUITests.xctest/uitestproblemUITests
  Reason: image not found)

If I manually copy over the required frameworks to .../Debug-iphonesimulator/uitestproblemUITests-Runner.app/Frameworks/ it works.

cd ~/Library/Developer/Xcode/DerivedData/uitestproblem-fzrkhrsghdyoseaobekimnrhrhpl/Build/Products/Debug-iphonesimulator/uitestproblemUITests-Runner.app/Frameworks/
# ls uitestproblemUITests-Runner.app/Frameworks/ shows only XCTest.framework
cp -r Alamofire/Alamofire.framework uitestproblemUITests-Runner.app/Frameworks/
cp -r Mockingjay/Mockingjay.framework uitestproblemUITests-Runner.app/Frameworks/
cp -r URITemplate/URITemplate.framework uitestproblemUITests-Runner.app/Frameworks/

I'm not very familiar with CocoaPods and Xcode (+ frameworks), but I assume that the Pods_uitestproblemUITests.framework should handle the above stuff somehow.

@LoganWright - In 1.0 your Podfile should look like: ( from the 1.0 migration guide )

target 'application-name-ios' do #name changed for client discretion
    pod 'Intrepid', '~> 0.3.0'
    pod 'Intrepid/Rx', '~> 0.3.0'
    pod 'Crashlytics', '3.6.0'
    pod 'M13BadgeView', '1.0.4'
    pod 'Swifternalization', '1.3.1'
    pod 'RxSwift', '~> 2.0'
    pod 'RxCocoa', '~> 2.0'
    pod 'Genome', '~> 2.0'

    # TODO: Add specifiers for version. Analytics
    pod 'Analytics/Segmentio'

    target 'UnitTests' do
      inherit! :search_paths
    end

    target 'UITests' do
      inherit! :search_paths
    end
end

In order to have the frameworks hooked up via search paths instead of duplicating the frameworks, can you test this?

@orta The project also fails with the Podfile you specified. It appears to have the same symptom of not adding the Copy Pods Frameworks build step. Even when I add this step, it seems to fail w/ the same corrupted message as posted by @mdio

I cleaned Xcode and removed derived data, deleted and reintegrated pods into the xcode project and all other general cleaning I could think of.

Am also having this issue. Have tried both on release version of Xcode (from App store) and Xcode 7.3.1. Using cocopods 1.0.0.beta.8. If I edit the pod file as per the first example, to change platform to iOS 9.2 for the UITests target, I have same issue. If I edit to use inherit! :search_paths instead of the shared_pods def then it breaks - starts complaining about bridging header for google analytics.

My pod file looks like this:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, "8.0"
use_frameworks!

def shared_pods
    pod 'Alamofire'
    pod 'KeychainAccess'
    pod 'SwiftDate','~> 1.2'
    pod 'Google/Analytics'
    pod 'ReachabilitySwift'
    pod 'NewRelicAgent'
end


target 'MyTarget' do
  shared_pods
end

target 'MyTargetTests' do
  shared_pods
end

target 'MyTargetUITests' do
  shared_pods
end

I can run Unit Tests fine but when I try to run UI Tests I get the following error:

Code Coverage Data Generation Failed … Unable to retrieve the profile data files from 'iPhone 6'.

In the Xcode console I see (edited for brevity):

Running tests...
The bundle ā€œ...{redacted}ā€ couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
Library not loaded: @rpath/Alamofire.framework/Alamofire
Runner.app/PlugIns/MyTargetUITests Tests.xctest/MyTargetUITests
Reason: image not found)

This issue has been inactive for some time and will be closed because we want to move forward with a clean slate after our 1.0 release. If you believe this is still relevant, please retest with the 1.0 release candidate and comment with a reproducible project in order for this to become actionable again. Thanks!

@neonichu This is still a problem with UITest targets. The "Embed Pods Frameworks" doesn't get included in the build phases. If I put it in manually, it works. Any idea where this left off on? This should be reopened as it's still affecting 1.0.0.rc.1

Related to issue #5250

@neonichu I can confirm that the workaround for this issue is by excluding Pods Frameworks entirely from UITests targets, as @KonradFalkowski-asideas has pointed out.

I can run UITests target with the main application as a test target as long as I don't use any of the Pods frameworks in my UITests files. In this case all interaction with the main application should be via XCUIElement or XCTest.

Unfortunately, with

@testable
import App

will import CocoaPods framework modules as well if I use it on the App module. So, if I have a specific dependency with 3rd party modules on my UITests files I have to move it elsewhere (probably creating new app test target).

I tested this on CocoaPods 1.0 from the Mac app

Still happens with latest cocoapods,
bash-3.2$ pod --version
1.0.1

platform :ios, '8.0'
use_frameworks!
...
target 'ShopYourWayUITests' do
    pod 'Nimble', '~> 3.2'
end

no "[CP] Embed Pods Frameworks" for ShopYourWayUITests target :(

Yep, like @bobrosoft, I'm seeing this too (Xcode 7.3).

I'm pretty sure someone submitted a PR with a fix and it was merged. Check the CHANGELOG. It will be in the next version probably.

Update:

  • Fix embedding frameworks in UI Testing bundles.
    Daniel Tomlinson #5250

@bre7 nice! unfortunately...I couldn't actually get cocoapods to work with the latest version. I built the gem from master and now get a crash when running pod install. 😢

I'll open up another issue (See #5542)

For UI Tests, do not specify anything in Podfile and they should work. Xcode 7.X.X UI Tests should not need any Pods. I faced same issue and had to remove pod declaration for UI Tests target from Podfile, delete all Pod scripts from Build Phases and it worked after pod install.

Had the same issue and adding inherit! :search_paths to the test target fixed it... Still not sure why.

I confirm that issue is fixed in ā€˜1.1.0.beta.1’

I had similar issues, upgrading to CocoaPods 1.1.0.beta.1 solved my issue. Thanks, guys!

Was this page helpful?
0 / 5 - 0 ratings