Libraries not found when using CocoaPods with iOS logic tests

前端 未结 14 1292
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 15:41

I am trying to write some iOS logic tests against classes in my project that use functionality from some of the libraries in my podspec. I am using the standard unit test bu

相关标签:
14条回答
  • 2020-11-29 16:34

    There is a solution I found here Unit Tests With CocoaPods:

    Open the project file in Xcode, then choose the Project (not the target), in the right panel, there is a section called Configurations. Choose Pods in the "Based on Configuration file" column for your test target.

    enter image description here

    0 讨论(0)
  • 2020-11-29 16:39

    I agree with the other answers telling that it is necessary to get the libraries linked to the test targets. However none of the suggestions so far helped me. As @fabb writes in a comment: "when testing, isSubclassOfClass: calls return NO where they should return YES. The only reason I can explain this is that the dependencies really get linked to both the main and the test target, and when the test target's bundle loader loads the main bundle, it cannot decide which class to take." I get the same problem with all the previous suggestions in this thread.

    The solution that I got to work was to update my Podfile to define specific Pods for my main target and my test target:

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

    It was necessary to specify a Pod for my test target even though I did not use any test specific Pods. Otherwise CocoaPods would not insert the necessary linking logic in my project.

    This link is what helped me come to this conclusion.

    0 讨论(0)
提交回复
热议问题