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
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.
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.