programing tip

Cocoapods를 사용한 Xcode 단위 테스트

itbloger 2020. 8. 16. 19:55
반응형

Cocoapods를 사용한 Xcode 단위 테스트


나는 지난 며칠 동안 이것으로 벽에 머리를 부딪 히고 있었지만 여러 Google / SO / Github 검색에도 불구하고 문제에 대한 해결책을 찾을 수 없습니다!

내가하려는 것은 Firebase 포드를 사용하는 내 앱에 대한 단위 테스트를 만드는 것입니다.

Xcode 7.3.1 및 Cocoapods 1.0.1을 사용하고 있습니다. 업데이트 : Xcode 8.0에 문제가 남아 있습니다 .

이 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

내 XCTest 클래스에서 나는

필수 모듈 'Firebase'누락

오류 @testable import MyApp

또는이 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

테스트는 빌드되지만 내 콘솔에는 다음과 같은 경고가 표시됩니다.

<-FirebaseClassName-> 클래스는 ... MyApp ... 및 ... MyAppTests ... 둘 다에서 구현됩니다. 둘 중 하나가 사용됩니다. 어느 것이 정의되지 않았습니까?


나는 같은 문제가 있었다. pod 'Firebase'테스트 대상 으로 이동 하여 해결했습니다 . Podfile을 다음과 같이 변경하십시오.

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

다음 :complete과 같이 상속을로 변경해보십시오 .

target 'MyAppTests' do
    inherit! :complete
end

중요한 것은 다른 사람이 당신의 repo를 체크 아웃 할 때 파일이나 다른 해커 pod update를 복사하지 않고도 평상시처럼 할 수있게 해줍니다 .xcconfig.


  1. 단위 테스트 대상 설정을 선택합니다.
  2. 빌드 설정으로 이동합니다.
  3. 헤더 검색 경로를 찾으십시오.
  4. 이 값 $ (SRCROOT) / Pods를 재귀 적으로 추가하면 Xcode가 경로를 확인합니다.


문제는 CocoaPods가 설정에 대한 자체 값을 생성 한 후 Firebase가 헤더 검색 경로에 특별한 작업을 수행하므로 CocoaPods가 테스트 대상으로 전달하기 위해이 변경 사항을 선택하지 않는다는 것입니다. 다음 두 가지 방법 중 하나로이 문제를 해결할 수 있습니다.

  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


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 your Tests target only under 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 the beta:

gem install cocoapods --pre

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


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


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

sudo gem install cocoapods --pre


I tried all the above and ran into various different errors, originally starting with Missing required module 'Firebase', then getting "Class ... is implemented in both ... " or linker issues if I tried to add Firebase Pods to my test target.

The solution that worked for me was to:

  1. Remove test target entirely from Podfile and run 'pod update' to ensure the XCode project is in sync.
  2. Open my test target's Build Settings and update header search paths to only include the following 3 items:
    • $(inherited) non-recursive
    • $(SRCROOT)/Pods/Headers/Public recursive
    • $(SRCROOT)/Pods/Firebase recursive

At this point cleaning the build folder, re-building then re-running the tests worked for me. Hope this helps someone!


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


Add "${PODS_ROOT}/Firebase/Core/Sources" to your Tests target only under Build Settings -> Header Search Paths


As @Will mentioned an issue around Header Search Paths after CocoaPods installation.

I have a project with multiple targets where pod 'Firebase' embedded into separate module, lets say MyProject-Shared. Firebase pod at 'Podfile' installed only for 'MyProject-Shared' target. Other modules, which wants to use 'MyProject-Shared' can't be compiled due an error:

'missing required module "Firebase" '

The trick in my case was to add following missing header search path at each target's Build Settings referencing to Analytics-Framework:

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

Please see pic below: Header Search Path

Hope it will save your time.


Adding ${SRCROOT}/Pods/Firebase/CoreOnly/Sources into the unit test target's "Header search paths" fixed the problem. Steps:

  1. Select your unit tests target
  2. Go to Build Settings
  3. Search for header search path
  4. Add ${SRCROOT}/Pods/Firebase/CoreOnly/Sources

enter image description here

After this the tests can run and the error will disappear.


Missing required module Firebase NO CocoaPods solution

For those who encounter the same problem but NOT using CocoaPods:

If you're using Firebase, than you have some folder containing Firebase.h and module.modulemap file. For example - YOUR_PROJECT_DIR/Linking

If your Main project target is working correct way, than you should go to ProjectSettings -> Targets. Select test target. Search for User headers and add the path to YOUR_PROJECT_DIR/Linking. Select recursive option and you should be good to go.

See the screenshot for more details:

enter image description here

참고URL : https://stackoverflow.com/questions/38216090/xcode-unit-testing-with-cocoapods

반응형