IT박스

iOS 로직 테스트와 함께 CocoaPod를 사용할 때 라이브러리를 찾을 수 없음

itboxs 2020. 6. 12. 21:52
반응형

iOS 로직 테스트와 함께 CocoaPod를 사용할 때 라이브러리를 찾을 수 없음


내 podspec의 일부 라이브러리에서 기능을 사용하는 프로젝트의 클래스에 대해 iOS 논리 테스트를 작성하려고합니다. Xcode에서 제공하는 표준 단위 테스트 번들을 사용하고 있습니다 (응용 프로그램 테스트는 아니지만 단위 테스트 만 가능).

예를 들어, Magical Record를 사용하고 해당 라이브러리를 podspec에 연결했습니다. 내 작업 공간의 포드 프로젝트에 있으며 앱이 시뮬레이터 또는 장치에서 실행될 때 예상대로 작동합니다. 그러나 Magical Record를 사용하는 객체를 테스트에 연결하려고하면 Magical Record에서 선택기를 찾을 수 없다는 링커 오류가 발생합니다. 논리 테스트 번들에서 HEADER_SEARCH_PATH를 업데이트하려고 시도했지만 CocoaPods가 만든 헤더 디렉토리로 하드 코딩했지만 운이 없습니다.

문제없이 CocoaPods 라이브러리를 사용하지 않는 클래스에 대해 단위 테스트를 실행할 수 있습니다.

내가 잘못 가고 있습니까? 컴파일러가 CocoaPods 라이브러리를 볼 수 있도록 다른 작업을 수행해야합니까?


CocoaPods 1.0이 이에 대한 구문을 변경했습니다. 이제 다음과 같이 보입니다 :

def shared_pods
    pod 'SSKeychain', '~> 0.1.4'
    ...
end

target 'Sail' do
    shared_pods
end

target 'Sail-iOS' do
    shared_pods
end

사전 CocoaPods 1.0 답변

당신이 사용하려는 것은 link_with에서 Podfile입니다. 다음과 같은 것 :

link_with 'MainTarget', 'MainTargetTests'

그런 다음 pod install다시 실행 하십시오.


내 앱의 주요 대상이 CocoaPods 라이브러리에서 설정을받는 방법을 살펴보면서이 사실을 알았습니다. CocoaPods에는 Pods.xcconfig라는 .xcconfig 파일이 포함되어 있습니다. 이 파일에는 모든 헤더 검색 경로가 포함됩니다.

프로젝트 탐색기에서 프로젝트를보고 정보 탭을 클릭하면 맨 위 섹션에 빌드 구성이 나열됩니다. 다른 구성에 대해 펼침 삼각형을 열면 기본 대상 아래에 포드가 표시됩니다. 드롭 다운을 클릭하고 로직 테스트 대상에도 포드를 추가해야했습니다.

구성 스냅 샷

또한의 설정을 복사했다 $(inherited)${PODS_HEADERS_SEARCH_PATHS}HEADER_SEARCH_PATHS / 내 주요 목표로하고 빌드 설정에서 논리 테스트 대상을 통해 복사합니다.

마지막으로, 로직 테스트 대상에 대한 라이브러리와 바이너리 빌드 링크 단계에서 libPods.a를 추가해야했습니다.

이것이 다른 사람을 도울 수 있기를 바랍니다.


여기에 CocoaPods를 사용한 단위 테스트 솔루션이 있습니다 .

Xcode에서 프로젝트 파일을 연 다음 프로젝트 (대상이 아닌)를 선택하십시오. 오른쪽 패널에는 구성이라는 섹션이 있습니다. 테스트 대상의 "구성 파일 기반"열에서 포드를 선택하십시오.

여기에 이미지 설명을 입력하십시오


라이브러리를 테스트 대상에 연결해야한다는 다른 답변에 동의합니다. 그러나 지금까지 제안 사항 중 어느 것도 도움이되지 않았습니다. @fabb는 다음과 같이 주석을 작성합니다. "테스트 할 때 isSubclassOfClass:호출은 YES를 반환해야하는 곳에서 NO를 반환합니다. 설명 할 수있는 유일한 이유는 종속성이 주 대상과 테스트 대상 모두에 연결되어 있고 테스트 대상의 번들이 로더가 기본 번들을로드하므로 어떤 클래스를 수행할지 결정할 수 없습니다. " 이 스레드의 모든 이전 제안과 동일한 문제가 발생합니다.

내가 해결해야 할 해결책은 내 주요 대상과 테스트 대상에 대한 특정 포드를 정의하기 위해 Podfile을 업데이트하는 것입니다.

target 'MyTarget' do
   pod 'AFNetworking', '~> 2.5.0'
   pod 'Mantle', '~> 1.5'
end

target 'MyTargetTests' do
   pod 'OCMockito', '~> 1.3.1'
end

이었다 필요 내가 어떤 테스트 특정 포드를 사용하지 않은 경우에도 내 테스트 대상에 대한 포드를 지정할 수 있습니다. 그렇지 않으면 CocoaPods가 프로젝트에 필요한 연결 논리를 삽입하지 않습니다.

이 링크 는이 결론에 도달하는 데 도움이되었습니다.


:exclusive => true응용 프로그램 테스트 대상에서 중복 된 기호 오류를 피하기 위해 추가 했습니다.

target 'myProjectTests', :exclusive => true do
   pod 'OCMock', :head
   pod 'XCTAsyncTestCase', :git => 'https://github.com/iheartradio/xctest-additions.git'
end

link_with 'myProject', 'myProjectTests'

응용 프로그램 테스트 대상을 논리 장치 테스트 대상으로 변경하면 링커 오류가 발생합니다. 를 제거한 후 :exclusive => true모든 것이 다시 작동합니다.

target 'myProjectTests', do
   pod 'OCMock', :head
   pod 'XCTAsyncTestCase', :git => 'https://github.com/iheartradio/xctest-additions.git'
end

link_with 'myProject', 'myProjectTests'

:exclusive => true외부의 모든 항목 do...end은에 연결해서는 안되며 myProjectTests이는 응용 프로그램 테스트 대상에서는 합리적이지만 논리 테스트 대상에서는 링커 오류가 발생합니다.


@Keith Smiley 솔루션에 따라 link_with를 사용할 수 있습니다.

공통 포드와 각 대상에 대한 세부 사항이있는 경우 "def"옵션을 사용하여 포드 그룹을 정의 할 수 있습니다. 배타적 대상에서 나중에 "def"를 사용하십시오.

def import_pods
    pod 'SSKeychain'
end

target 'MyProjectTests', :exclusive => true do
  import_pods
end

target 'MyProject', :exclusive => true do
  import_pods
  pod 'Typhoon'
end

위의 예에서 두 대상에 'SSKeychain'을 추가하고 'MyProject'대상에만 'Typhoon'을 추가했습니다.


이 문제에 대한 나의 해결책은 Podfile을 다음과 같이 두 대상 모두에 라이브러리를 포함하도록 변경하는 것입니다.

target "MyApp" do  
    pod 'GRMustache', '~> 7.0.2'
end

target "MyAppTests" do
    pod 'GRMustache', '~> 7.0.2'
end

그리고 swift를 사용하고 있기 때문에 MyApp-Bridging-Header.h파일 을 포함하도록 테스트 대상을 구성해야했습니다 . (빌드 설정 탭의 Swift Compiler 그룹에서)


I had a similar occurrence when I lost some library files during some version control. I still saw the library file in my Pods but with the actual code missing, XCode said it was gone. To my dismay, running 'pod install' wasn't immediately bringing the lost files back.

I had to remove and replace the pod manually by doing the following:

  1. Remove the library from the Podfile
  2. Run 'pod install' to remove the library completely
  3. Put the library back into the Podfile
  4. Run 'pod install' again

This should put the library in question back in it's original form.


It's also worth noting that if you have libPods.a added twice, you'll get some nasty error like this:

232 duplicate symbols for architecture i386

To fix it, just delete one of the libPods.a references in your Project Explorer.


As of CocoaPods 1.x, there's a new way to declare shared dependencies between a target and the corresponding test target. I'd been using the accepted solution by Mark Struzinski to this point, but using this method yielded a massive number of warnings when running my tests that:

Class SomeClass is implemented in both /Path/To/Test/Target and /Path/To/App/Target. One of the two will be used. Which one is undefined.

With CocoaPods 1.x we can declare our -Test target as inheriting via the parent target's search paths, like so:

target 'MyApp' do
    pod 'aPod'
    pod 'anotherPod'
    project 'MyApp.xcodeproj'
end
target 'MyAppTests' do
    inherit! :search_paths
    project 'MyApp.xcodeproj'
end

This will result in the -Test target having access to the dependencies of the app target, without multiple binary copies. This has seriously sped up test build times for me.


Try This it's working for me ,

We need to set Pods in Configurations ,

The Project->Info->Configurations in the Xcode project (your project) should be set to main project 'Pods' for Debug, Release (and what else you have). See "Headers not found – search paths not included"

여기에 이미지 설명을 입력하십시오

Hope this is help to some one .


I am working with GoogleMaps Objective-C POD integration on iOS with my Swift app and so for me the issue was that the Test target didn't have a reference to the Bridge Header File (SWIFT_OBJC_BRIDGING_HEADER) in the Build Settings. Make sure both your app and test app targets point to that so that the 3rd party API calls (maps API, etc.,) can be used in swift unit tests.


Next syntax gives best result for me (tested under cocoapod v.1.2.1):

https://github.com/CocoaPods/CocoaPods/issues/4626#issuecomment-210402349

 target 'App' do
    pod 'GoogleAnalytics' , '~> 3.0'
    pod 'GoogleTagManager' , '~> 3.0'

     pod 'SDWebImage', '~>3.7'
     platform :ios, '8.0'
     use_frameworks!

     target 'App Unit Tests' do
         inherit! :search_paths
     end
 end

Without this I have warnings while test run about duplicate symbols.

After this warnings were disappear.


I had issues using OpenCV under XCTest. It was giving me linker errors of Undefined symbols for architecture arm64 for classes like cv::Mat. I am installing OpenCV through CocoaPods using pod 'OpenCV', '~> 2.0' under the main target. No matter how hard I tried to put the OpenCV dependency under the test target or use inherit! :search_paths none of it worked. The solution was to create an abstract_target like so:

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

abstract_target 'Shows' do
  pod 'RMVision', path: '../..'
  pod 'RMShared', path: '../../../RMShared'
  pod 'OpenCV', '~> 2.0'

  target 'RMVisionSample' do
    # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
    # use_frameworks!

    # Pods for RMVisionSample
  end

  target 'RMVisionSampleTests' do
    # inherit! :search_paths
    # Pods for testing
  end

  target 'RMVisionBenchmarks' do
    # inherit! :search_paths
    # Pods for testing
  end

end 

Also useful are the pod deintegrate & pod clean commands which help to cleanup the project and make sure that you start fresh when testing. You can install those two using [sudo] gem install cocoapods-deintegrate cocoapods-clean.

참고URL : https://stackoverflow.com/questions/14512792/libraries-not-found-when-using-cocoapods-with-ios-logic-tests

반응형