Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Unit Testing with Cocoapods

People also ask

What is Podspec in CocoaPods?

A Podspec, or Spec, describes a version of a Pod library. One Pod, over the course of time, will have many Specs. It includes details about where the source should be fetched from, what files to use, the build settings to apply, and other general metadata such as its name, version, and description.

Does CocoaPods use Ruby?

CocoaPods is built with Ruby and it will be installable with the default Ruby available on macOS. You can use a Ruby Version manager, however we recommend that you use the standard Ruby available on macOS unless you know what you're doing.

Is CocoaPods a Ruby gem?

What is CocoaPods? CocoaPods is a dependency manager for Cocoa and Cocoa Touch projects which covers macOS, iOS, watchOS and tvOS development. It is written in Ruby and distributed through RubyGems.


I had the same issue. I solved it by moving pod 'Firebase' to my test target. Change your Podfile to this:

platform :ios, '9.0'
use_frameworks!
inhibit_all_warnings!

target 'MyApp' do
    pod 'Firebase/Auth'
    pod 'Firebase/Database'
    pod 'Firebase/Storage'

    target 'MyAppTests' do
        inherit! :search_paths
        pod 'Firebase'
    end
end

Try changing the inheritance to :complete, as in:

target 'MyAppTests' do
    inherit! :complete
end

Importantly it allows anyone else checking out your repo to just do a pod update as usual without having to copy .xcconfig files or other hackery just to build.


  1. Select your Unit Test Target setting.
  2. Go to Build Settings.
  3. Look for Header Search Paths.
  4. Add this value $(SRCROOT)/Pods with recursive, then Xcode will resolve the path for you.

Example


The issue is that Firebase does something special with the Header Search Paths after CocoaPods generates its own value for the setting so CocoaPods doesn't pick up on this change in order to carry it over to the test target. You can solve this one of two ways:

  1. Locate MyAppTests.<configuration>.xcconfig in the file navigator and add the following to HEADER_SEARCH_PATHS:

    ${PODS_ROOT}/Firebase/Analytics/Sources [*]

  2. Find the setting for Header Search Paths in Build Settings and add that same value as in option 1 to the list. You shouldn't need to set it as recursive.

* As per AKM's comment, this changed to ${PODS_ROOT}/Firebase/Core/Sources in version 3.14.0


Three Steps before I could get this to work:

CocoaPods : 1.5.0 Swift 4 Firebase : 4.13.0

Step 1: Make sure to add the following target block into your podfile.

# Uncomment the next line to define a global platform for your project
platform :ios, '11.3'

target 'TIMII' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

# Pods for TIMII
pod 'Firebase/Core'
pod 'Firebase/Database'
pod 'Firebase/Auth'
pod 'Firebase/Storage'

    target 'TIMIITests' do
        inherit! :search_paths
        pod 'Firebase/Core'
    end

end

Step 2: Within the YourAppTests Project Navigator Build Settings tab. Find the Header Search Path row and add to Debug the following line

$(inherited) ${PODS_ROOT}/Firebase/Core/Sources

Step 3: In terminal run:

pod update