Testing Xcode Block with Cocoapods

I’ve been banging my head on the wall for several days, but despite several Google / SO / Github searches, I can’t find a solution to the problems I have.

All I'm trying to do is create some unit tests for my application that use Firebase modules.

I am using Xcode 7.3.1 and Cocoapods 1.0.1. Update: The problem remains with Xcode 8.0

With this podfile:

platform :ios, '9.0' use_frameworks! inhibit_all_warnings! target 'MyApp' do pod 'Firebase' pod 'Firebase/Auth' pod 'Firebase/Database' pod 'Firebase/Storage' target 'MyAppTests' do inherit! :search_paths end end 

In my XCTest class, I get

Missing required Firebase module

error with @testable import MyApp

Alternatively with this podfile:

 platform :ios, '9.0' use_frameworks! inhibit_all_warnings! def common_pods pod 'SwiftyTimer' pod 'Firebase' pod 'Firebase/Auth' pod 'Firebase/Database' pod 'Firebase/Storage' end target 'MyApp' do common_pods end target 'MyAppTests' do common_pods end 

Tests are being built, but my console is littered with warnings, for example:

The <-FirebaseClassName-> class is implemented as in ... MyApp ... and ... MyAppTests ... One of the two will be used. Which one is undefined

+102
ios unit-testing xcode cocoapods xctest
Jul 06 '16 at 3:54 on
source share
13 answers

The solution for me was updating cocoapods to version 1.1.0.rc.2.

sudo gem install cocoapods --pre

+3
Sep 29 '16 at 0:00
source share

I had the same problem. I solved this by moving the pod 'Firebase' to my test target. Change your subfile:

 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 
+77
Jul 07 '16 at 20:36
source share

Try changing the inheritance to :complete , as in:

 target 'MyAppTests' do inherit! :complete end 

It is important that someone else check your repo by simply doing pod update as usual, without having to copy the .xcconfig files or other hackers just for assembly.

+53
Nov 17 '16 at 19:41
source share
  1. Select the target setting.
  2. Go to the "Build Settings" section.
  3. Find heading search paths.
  4. Add this value to $ (SRCROOT) / Pods with recursive, then Xcode will solve the path for you.

example

+43
Sep 10 '18 at 6:43
source share

The problem is that Firebase does something special with header search paths after CocoaPods generates its own value for the parameter, so CocoaPods does not pick up this change to transfer it to the test object. You can solve this one of two ways:

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

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

  • Find the settings for the Header Search Path in the build settings and add the same value as in option 1 to the list. You do not need to set it as recursive.

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

+33
20 Sep '16 at 19:49
source share

The problem is recorded in the firebase project here:

https://github.com/firebase/firebase-ios-sdk/issues/58

There is a workaround:

Add "$ {PODS_ROOT} / Firebase / Core / Sources" to the target audience only in the build settings -> Header Search Paths

but this is also fixed by upgrading to CocoaPods 1.4.0 or later, which is a better solution.

At the time I'm writing this (November 2017), cocoapods 1.4.0 is still in beta, so to install it you need to explicitly request a beta version:

 gem install cocoapods --pre 

This and then doing pod install solved the problem of running my tests.

+7
Nov 16 '17 at 23:42 on
source share

Three steps before I can get this to work:

CocoaPods: 1.5.0 Swift 4 Firebase: 4.13.0

Step 1. Be sure to add the following target block to your file.

 # 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: On the tab “Configure tab“ Configure project ”on the tab“ Project navigator. ”Find the header search path line and add the following line to Debug

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

Step 3: In a terminal run:

pod update

+6
May 6 '18 at 23:24
source share

I tried all of the above and encountered various errors, initially starting with the Missing required module 'Firebase' , then getting "Class ... is implemented in both ... " or linker problems if I tried to add Firebase modules to my testing target .

The solution that worked for me was this:

  1. Completely remove the test target from the Podfile and run "pod update" to make sure the Xcode project is in sync.
  2. Open my test target Build Settings and update the header search paths to include only the following 3 elements:
    • $(inherited) non-recursive
    • $(SRCROOT)/Pods/Headers/Public recursive
    • $(SRCROOT)/Pods/Firebase recursive

At this point, cleaning the build folder, reassembling and re-running the tests helped me. Hope this helps someone!

+3
Feb 08 '19 at 11:03
source share

I had a similar problem. Referring to your question, I copied the contents of my MyApp.<configuration>.xcconfig file to my MyAppTests.<configuration>.xcconfig . I cleaned up and built tests, and it worked.

+2
Oct 24 '16 at 1:48
source share

Add "$ {PODS_ROOT} / Firebase / Core / Sources" to the target audience only in Build SettingsHeader Search Contours

+1
Nov 06 '17 at 12:22
source share

Like @ You mentioned a problem around header search paths after installing CocoaPods.

I have a project with several goals, where the "Firebase" pod is built into a separate module, say MyProject-Shared . Firebase pod in 'Podfile' is set for MyProject-Shared only. Other modules that want to use "MyProject-Shared" cannot be compiled due to an error:

'missing required' firebase 'module'

The trick in my case was to add the following missing header search path in each Build Settings target setting, referencing the Google Analytics-Framework:

"${PODS_ROOT}/Firebase/CoreOnly/Sources"

See Fig. Below: Header search path

Hope this saves you some time.

+1
May 24 '18 at 4:41
source share

Adding ${SRCROOT}/Pods/Firebase/CoreOnly/Sources to the target of the Header Search Paths unit test ${SRCROOT}/Pods/Firebase/CoreOnly/Sources problem. Stages:

  1. Choose a unit test goal
  2. Go to Build Settings
  3. Search header search path
  4. Add $ {SRCROOT} / Pods / Firebase / CoreOnly / Sources

enter image description here

After that, tests can be run and the error will disappear.

0
Aug 30 '19 at 7:24
source share

Missing required module Firebase NO CocoaPods solution

For those facing the same problem but NOT using CocoaPods:

If you use Firebase, you have a folder containing the Firebase.h and module.modulemap . For example - YOUR_PROJECT_DIR/Linking

If the goal of your main project is working correctly, then you should go to ProjectSettings → Targets. Select a test target. Find User headers and add the path to YOUR_PROJECT_DIR/Linking . Select the recursive option and you will be well off.

See the screenshot for more details:

enter image description here

0
Sep 10 '19 at 11:59 on
source share



All Articles