The test runner failed to load the test bundle - ios

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

Go to your test logs in Derived data folder:
~/Library/Developer/Xcode/DerivedData/APP_BUILD_FOLDER/Logs/Test
You will find a .xcresult test result bundle, right-click it and choose Show package contents and in 1_Test/Diagnostics folder, you should find run/crash log for your tests.
This log will give you an exact cause of your fail, you can post it here if you don't know what to do with it after you find it, we will help you :-)
Without this log, cause of your issue could be literally anything, since this is rather generic xcbuild fail message.

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

Oky, thx for logs this should fix your issue:
target 'Framework' do
use_frameworks!
pod 'RealmSwift', '~> 3.13.1'
target 'FrameworkTests' do
inherit! :search_paths
pod 'RealmSwift', '~> 3.13.1'
end
end
You don't have the RealmSwift library installed for your test target in pods, only for your app, as you can tell from log:
...Library not loaded: #rpath/Realm.framework/Realm referenced from...MyFrameworkTests.xctest...
Add code above to your podfile and run pod update :-)

Similar modification helped me.
use_frameworks!
target 'Framework' do
pod 'RealmSwift', '~> 3.13.1'
end
target 'FrameworkTests' do
pod 'RealmSwift', '~> 3.13.1'
end
Feel free to use "def" link

I encountered this issue recently when attempting to run our UI Tests target after our min deployment target was updated from 11.0 to 13.2, which failed immediately on launch. Oddly enough, updating the target all the way up to 12.4 worked just fine, but anything >= 13.0 resulted in the error
The bundle "MyAppUITests" couldn't be loaded. Try reinstalling the bundle.
The single change that resolved it (beyond ensuring that deployment target was set consistently across all targets, and in the Podfile) was to clear out the value we had listed in the BUNDLE_LOADER Build Setting within our UI Test Target.
Before:
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp";
After:
BUNDLE_LOADER = "";

Related

Xcode 10.1: Pods not compiling when running UITest

I am trying to implement UITests in an application I'm working on.
When I am in my UITests.swift file and I try to run the app from a test, Xcode gives the following error for some of the pods I'm using:
Command CompileSwift failed with a nonzero exit code
It gives this error for a bunch of pods that are compiling just fine when running the regular project:
My PodFile looks as follows:
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
source 'https://github.com/cocoapods/specs.git'
project 'Project.xcodeproj'
use_frameworks!
# Define all thirdparty pods we need
def thirdparty
pod 'Moya', '~> 11.0'
pod 'Alamofire'
pod 'SwiftyJSON'
pod 'Differ'
.. a bunch of other pods
end
# Pods for Project project
target 'Project' do
thirdparty
end
# Pods for ProjectTests
target 'ProjectUITests' do
thirdparty
pod 'Nimble'
end
I'm having a hard time reasoning why this is happening, as my project normally compiles just fine. Other posts on S.O. regarding this problem report that the problem also occurs when building the project rather than just running for a test
Question How can I make sure that all pods I use in my project, also compile correctly when building from a UITest?
How can I make sure that all pods I use in my project, also compile correctly when building from a UITest?
The only way to know whether something will build or not is to try to build it. So when you change your CocoaPods configuration, even if that's just to update to a newer version of one or more pods, you need to try building each target.
target 'ProjectUITests' do
thirdparty
pod 'Nimble'
end`
According to your Podfile, you've got the pod Nimble being used only in the ProjectUITests target. If that's the only target that fills to build, then it seems likely that that pod is the culprit.
Except for one case (at least as far as you've shown) your Podfile doesn't specify versions for the various pods that it specifies. If you leave out the version for a given pod, your project will use the latest available version. That means that anytime you update your pods you'll pull down the latest version, even if that new version contains breaking changes. It would be safer to specify the version that you know works, or at least to limit the version to minor version and patch updates, like:
pod 'Nimble', '~>7.0'
That will let CocoaPods automatically use the latest version up to but not including 8.0. If the pod developer properly follows the semantic versioning scheme, that should ensure that you don't inadvertently pull in any breaking changes.
The problem is that target :AppModuleTests do do not have an app host and you are using inherit! :search_paths. This means that this target would find the dependencies to load them from the host but in this case there is none.
target TestApp do
pods
target :AppModuleTests
end
This worked for me.

Cocoapods testing linker error

Whenever I build my testing target (the standard target that Xcode generates), the build fails with an cryptic error:
framework not found Pods_AppName_AppNameTests
which I take to mean the pod generated target for my tests can't be found.
My podfile is pretty simple:
use_frameworks!
target 'AppName' do
pod 'ReactiveCocoa'
pod 'RealmSwift'
pod 'ObjectMapper'
pod 'Moya'
pod 'Moya/ReactiveCocoa'
pod 'pop'
pod 'Heimdallr'
pod 'Heimdallr/ReactiveCocoa'
pod 'Alamofire'
pod 'AlamofireImage'
pod 'SwiftDate'
pod 'DropdownAlert'
pod 'NibDesignable'
target 'AppNameTests' do
pod 'Quick'
pod 'Nimble'
end
end
I'm using Cocoapods 1.0.1.
EDIT:
It is NOT the format of my podfile. This is the default setup given to me by running pod init. There may very well be a bug in cocoapods but the format is correct.
EDIT 2:
If I include:
inherit! search_paths
in my test target, the tests fail saying:
The bundle “MyApp_Tests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
Without that line, the tests also fail to build but this time with a linker error:
Ld /Users/travis/Library/Developer/Xcode/DerivedData/Reactify-fqgxzcgedmqljrangqdkxpwdfxne/Build/Intermediates/Reactify.build/Debug-iphonesimulator/Reactify_Tests.build/Objects-normal/i386/Reactify_Tests normal i386
That particular error is from Travis but I get the same one in Xcode locally.
I've been battling with this the last week as well -- the "solution" I eventually found to work reliably was to add inherit! search_paths, pod install, then remove it, and pod install again, from the test target, like this:
source 'https://github.com/CocoaPods/Specs.git'
project 'CityWeather/CityWeather.xcodeproj'
install! 'cocoapods',
:deterministic_uuids => false
use_frameworks!
platform :ios, '9.3'
abstract_target 'CityWeather_Base' do
<... pod list here, contents don't seem to matter ...>
target 'CityWeather' do
end
target 'CityWeatherTests' do
# NB. If it starts refusing to link the test frameworks,
# adding and then removing inherit! :search_paths here appears to help.
#inherit! :search_paths
end
end
That's less hassle at least than creating a new target every time it happens to you, which judging by my last week I predict to happen to you shortly. Very annoying. Spent as much time as I could spare to try to deduce from the commit logs where the problem occurs, but it's not straightforwardly obvious. I'll update here if I manage to find the time to figure out the problem enough to open a useful issue. But in the meantime, hopefully my "solution" will improve your productivity somewhat.
It's the strangest thing and I absolutely tried this before, but I just deleted the test target, created a new one, and lo and behold, it works. The sole difference, as far I can tell, between the two targets is one was called MyApp_Tests and the other MyApp_ExampleTests. I'd be surprised if that was the cause but at this point it's hard to tell.
I will say though as a side note, the project I was referring to is not the only project I've seen this happen with. The last four of my projects have encountered this error, all created since Cocoapods 1.0.0. That leads me to believe that there's some hidden bug in the Cocoapods test setup which I'll have to investigate more.
Additionally, deleting the test target and making a new one only seemed to work in this particular case. In other projects, the error persists. And I can tell it's more than just my local setup because my travis builds would also fail consistently.

Cocoapod issues with swift/objc project and testting target

I'm working with a mostly OBJc project,Tests are done with Cedar. I've started including swift and am having issues with cocoapod frameworks in my test target
Cocoapods version is 0.39.0 (upgrading to the beta gave me more issues so sticking with stable for now)
My podfile looks like this:
def test_pods
pod 'Cedar'
pod 'PivotalCoreKit/Development'
end
def app_pods
pod 'PivotalCoreKit'
pod 'JSONWebToken'
pod 'RealmSwift'
pod 'SwiftyJSON'
end
target 'App' do
use_frameworks!
app_pods
end
target 'AppTests' do
use_frameworks!
test_pods
end
The issue I'm having right now is when building for tests, it gives me "Can't find symbol" errors for all the pods in the main app target.
What I've done:
Added pods to both targets(produces error saying class exists twice)
Tried setting use frameworks only for app target
link_with, produces the same result as if adding them to both targets
I have a full swift app, that works just fine when setting the test pods to only the test target, so I'm assuming that because this is a hybrid code base, I'm seeing some issues.

Watchkit & Realm 0.92.3

The Swift integration of a new Realm-DB (realm 0.92.3) under Xcode 6.3 and iOS10.10.3 basically works for the iPhone (not for the Apple-Watch yet). The integration of the same realm-framework under Watchkit (i.e. Apple-Watch) does not work yet.
The RealmSwift.framework is integrated (dragged into) the Embedded-Binaries as described here1 and here2.
See screenshot below :
When running the Watchkit-App with the simulator the following error occurs :
dyld: Library not loaded: #rpath/libswiftCore.dylib
Referenced from: /Users/XXX/Library/Developer/CoreSimulator/Devices/3FE99-9-4C4C2/data/Containers/Bundle/Application/8B4-DF19F34-222973/MyApp.app/PlugIns/MyApp WatchKit Extension.appex/MyApp WatchKit Extension
Reason: image not found
(lldb)
What is still wrong ???
The Framework-Search-Path of the main-app is set. The ones for MyApp Watchkit Extension and MyApp Watchkit App are not set. Setting them does not change the above error. What is still missing ???
I would recommend that you use CocoaPods.
I did it like you did, with dynamic frameworks, but when I try to submit my application to iTunes Connect using Xcode's Organizer, I could not because of the nested frameworks. Realm.framework is inside RealmSwift.framework, and that is not okay with Apple. So I try and try but nothing helped…
Then I used CocoaPods and everything worked as it should.
Here are instructions for CocoaPods installation:
Install CocoaPods 0.37.1 or later ([sudo] gem install cocoapods).
In your Podfile, add use_frameworks! and pod 'RealmSwift' to your main and test targets.
From the command line, run pod install.
Use the .xcworkspace file generated by CocoaPods to work on your project!
This Podfile finally did it for me (see below). Everything worked after that...
To install just open a terminal, go to your App's folder (where you place the Podfile) and type
pod install
After that make sure to open from now on the "MyApp.xcworkspace" (no longer "MyApp.xcodeproj") and you are all set !
Here is the podfile that worked :
xcodeproj 'MyApp.xcodeproj'
workspace 'MyApp.xcworkspace'
platform :ios, '8.3'
source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
link_with 'MyApp', 'MyApp WatchKit Extension'
def shared_pods
pod 'RealmSwift', '>= 0.93.2'
end
target 'MyApp' do
shared_pods
end
target 'MyAppTests' do
shared_pods
end
target 'MyApp WatchKit Extension' do
shared_pods
end

Cocoapods missing pod include files when removing all test pods

I have an iOS project I've been working on for some time, successfully, in which I used several pods for my main target, and then a couple more for my test target. Everything went swimmingly.
I was using a pod for tests, Expecta, because I needed to test asynchronous code. Now that Apple has added support for asynchronous testing in the latest Xcode, I rewrote my tests to use that, and want to remove Expecta from my project.
After doing that, my tests no longer compile, with errors about the header files from the pods no longer being found. For instance, `'FacebookSDK/FacebookSDK.h' file not found' error compiling one of my tests.
I've tried deleting all the Cocoapod-generated stuff and redoing it from pod install with no luck.
Versions: Cocoapods 0.35.0, Xcode 6.1.1, OS X 10.10.1.
My new, no-test-pods Podfile is:
# Uncomment this line to define a global platform for your project
platform :ios, '7.0'
target 'Meow' do
pod 'AFNetworking', '2.4.1'
pod 'TestFlightSDK', '3.0.2'
pod 'AWSiOSSDKv2/S3', '2.0.11'
pod 'Facebook-iOS-SDK', '3.20.0'
pod 'TTTAttributedLabel', '1.10.1'
pod 'DTCoreText', '1.6.14'
pod 'ReactiveCocoa', '2.3.1'
end
target 'MeowTests' do
end
Removing the MeowTests target hasn't helped either.
While I was typing the above :) I found this question; which says to add a link_with line to my podfile, and change the configuration file setup in the Info pane of my Project.
However, because I was removing the last pod from my test target, I also needed to delete the CocoaPods-specific phases from my test target. In the Build Phases tab, I removed Check Pods Manifest.lock and Copy Pods Resources.
Now my tests run fine. (And I can start rewriting them in Swift :) )

Resources