Add Cocoapods to Tests Target Too

Add cocoapods to tests target too?

Ok, there is a simple solution, see answer above to get this working automatically. I had to select Pods/Pods configuration file for tests target in project info.

configuration file settings

Cocoapod not being imported during build for test target

Okay well I have made it work now by adding the Pods project inside the PusherSwift project. I'm not entirely sure why that made it work but it basically just seemed to make the frameworks available to the PusherSwift targets.

How to use unit test cases (added to a development pod as test_spec) in the main app target?

Once you have the target you need to edit your scheme to make it run the tests!

Edit scheme

Then set it to be tested (by adding it to the +)

Include tests in the test list

Also it is added automatically to the build

Add test to build

And its done! :D

Libraries not found when using CocoaPods with iOS logic tests

I figured this one out by looking at how the main target of my app was receiving settings from the CocoaPods library. CocoaPods includes an .xcconfig file named Pods.xcconfig. This file contains all of the header search paths.

If you look at your project in the project navigator and click the Info tab, you will see your build configurations listed on the top section. If you open the disclosure triangle for your different configurations, you will see Pods listed under your main target. I had to click the drop down and add Pods to the logic test target as well.

Configurations Snapshot

I also had to copy the settings of $(inherited) and ${PODS_HEADERS_SEARCH_PATHS} from my main target and copy them over to the logic test target under Build Settings/HEADER_SEARCH_PATHS.

Finally, I had to add libPods.a in the Link Binary with Libraries build phase for my logic tests target.

Hope this is able to help someone else.

How do I specify multiple targets in my podfile for my Xcode project?

Since CocoaPods 1.0 has changed the syntax, instead of using link_with, do something like:

# Note; name needs to be all lower-case.
def shared_pods
pod 'SSKeychain', '~> 0.1.4'
pod 'INAppStoreWindow', :head
pod 'AFNetworking', '1.1.0'
pod 'Reachability', '~> 3.1.0'
pod 'KSADNTwitterFormatter', '~> 0.1.0'
pod 'MASShortcut', '~> 1.1'
pod 'MagicalRecord', '2.1'
pod 'MASPreferences', '~> 1.0'
end

target 'Sail' do
shared_pods
end

target 'Sail-iOS' do
shared_pods
end

Old answer Pre CocoaPods 1.0:

Yes there is a better way! Check out link_with where you can do link_with 'MyApp', 'MyOtherApp' to specify multiple targets.

I use this with unit tests like link_with 'App', 'App-Tests' (beware of spaces in target's names).

Example:

platform :osx, '10.8'

link_with 'Sail', 'Sail-Tests'

pod 'SSKeychain', '~> 0.1.4'
pod 'INAppStoreWindow', :head
pod 'AFNetworking', '1.1.0'
pod 'Reachability', '~> 3.1.0'
pod 'KSADNTwitterFormatter', '~> 0.1.0'
pod 'MASShortcut', '~> 1.1'
pod 'MagicalRecord', '2.1'
pod 'MASPreferences', '~> 1.0'


Approach using abstract_target:

In below example, the 'ShowsiOS', 'ShowsTV' and 'ShowsTests' targets have their own separate pods, plus ShowsKit inherited, because they are all child of the dummy target 'Shows'.

# Note: There are no targets called "Shows" in any of this workspace's Xcode projects.
abstract_target 'Shows' do
pod 'ShowsKit'

target 'ShowsiOS' do
pod 'ShowWebAuth'
end

target 'ShowsTV' do
pod 'ShowTVAuth'
end

# Our tests target has its own copy
# of our testing frameworks
# (beside inheriting ShowsKit pod).

target 'ShowsTests' do
inherit! :search_paths
pod 'Specta'
pod 'Expecta'
end
end

Cocoapods testing linker error

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.

Set deployment target for CocoaPods's pod

While some development versions of CocoaPods (as well as pre-1.0 versions) may have propagated the deployment target of the project down to the pods, this is no longer the case in 1.0. To work around this, the current developer recommends using a post-install hook.

Here's a brute force approach to force a hard-coded deployment target for every pod in the generated Pods project. Paste this at the end of your Podfile:

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.2'
end
end
end


Related Topics



Leave a reply



Submit