Xcode Unit Testing with Cocoapods
Solution 1
The solution for me was to update cocoapods to version 1.1.0.rc.2.
sudo gem install cocoapods --pre
Solution 2
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
Solution 3
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.
Solution 4
- Select your Unit Test Target setting.
- Go to Build Settings.
- Look for Header Search Paths.
- Add this value
$(SRCROOT)/Pods
with recursive, then Xcode will resolve the path for you.
Here is Example
Solution 5
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:
-
Locate
MyAppTests.<configuration>.xcconfig
in the file navigator and add the following toHEADER_SEARCH_PATHS
:${PODS_ROOT}/Firebase/Analytics/Sources
[*] 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
doovers
Mechanical Engineer turned full-stack software developer. Passionate about technology and all things programming. My work is also my hobby and the ability to face new challenges and learn new things on a daily basis is what drives me.
Updated on July 08, 2022Comments
-
doovers almost 2 years
I've been banging my head against a wall with this for the last few days but despite multiple Google/SO/Github searches I can't find a resolution to the issues I'm having!
All I'm trying to do is create some unit tests for my app which makes use of Firebase pods.
I'm using Xcode 7.3.1 & Cocoapods 1.0.1. Update: Issue 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 module 'Firebase'
error at
@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
The tests build but my console is littered with warnings e.g.:
Class <-FirebaseClassName-> is implemented in both ...MyApp... and ...MyAppTests... One of the two will be used. Which one is undefined
-
doovers almost 8 yearsThanks but I just tried that and I still have the "Class ... is implemented in both ... " issue.
-
doovers over 7 yearsTried that but still getting same warnings
-
Zeb over 7 yearsUnfortunately it doesn't work for me...I have to take back my upvote!
-
doovers over 7 yearsSorry it didn't help you out guys, not sure why it solved the problem for me and not you...
-
SauloT over 7 yearsThis was the only solution that worked for me. Thanks! I'm thinking about do a post install processing in the Podfile doing this
-
Diogo T over 7 yearsThis also have the "Class ... is implemented in both ... " issue
-
AKM about 7 yearsAs of Firebase 3.14.0 This solution is valid, however the patch changed to
${PODS_ROOT}/Firebase/Core/Sources
-
UKDataGeek about 7 yearsI am on 1.20 and no luck
-
Dirty Henry about 7 yearsIt worked for me but it still doesn't make sense to me. It's not the 1st time I can tell Firebase are setting up their podspecs weirdly, cf. twitter.com/dirtyhenry/status/836240557311684608 but the Firebase team doesn't reply :(
-
Paulo Mattos about 7 yearsNew path worked for me as well! I'm running CocoaPods version 1.2.0, but keep in mind I also had to add
inherit! :search_paths
to the test target in thePodfile
. -
Jonny almost 7 years2. does not work for me. Using Firebase 3.x (not the newest 4.x)
-
CMont almost 7 yearsIt made the compile time error disappear, but caused this one at runtime: clang: error: linker command failed with exit code 1 (use -v to see invocation)
-
CMont almost 7 yearsIssue can be followed here: github.com/firebase/firebase-ios-sdk/issues/58
-
blwinters over 6 yearsMaking this change didn't immediately clear the warning, but it was resolved after I ran
pod install
. -
smapps over 6 yearsWorked for me as well! Thanks :)
-
ArgaPK over 6 yearswhat is it "PODS_ROOT" ??
-
ArgaPK over 6 yearsWhat is it ? PODS_ROOT
-
JosephH over 6 years@ArgaPK It's a variable that cocoapods sets. Just paste exactly what I wrote between the ""s into Xcode. Really the best way is to upgrade your CocoaPods to >= 1.4.0.
-
Karthick Vadivel over 6 yearsit will fetch directory for pod
-
ArgaPK over 6 yearsHalf problem solved. and other half is solved by Add "${PODS_ROOT}/Firebase/Core/Sources" to your Tests target only under Build Settings -> Header Search Paths
-
ArgaPK over 6 yearsHalf Problem solved and in other half include pod 'Firebase' in test target.
-
Stacy Smith about 6 years@JosephH updating my cocoapods to 1.5.2 didn't solve the problem, unfortunately.
-
JosephH about 6 years@AnastasiaKovaleva did you run
pod install
after upgrading? -
Stacy Smith almost 6 years@JosephH Running
pod install
solved my problem! Thanks a lot! -
Ali Parr almost 5 yearsAfter trying everything else on this thread - this was the only answer that got things working for me. Thank you!
-
jawad over 4 yearsAfter you make this change do not forget to run
pod install
in order to update project dependencies ;) -
Rahul K Rajan over 4 yearsThank you @Kanika Sharma
-
Saran over 3 yearsThis is what worked for me. No need to touch podfile or xcconfig. Thanks for sharing.
-
Tim Chen about 3 yearsThis works perfectly. Thank you. Any documentation on the syntax? What does
: MyAppTests
mean? -
Bruce about 3 yearsThis works for me as well, and syntax looks the simplest!