简体   繁体   中英

Cocoapods library doesn't correctly return isKindOfClass during unit tests

I have a library that I installed with Cocoapods (ECSlidingViewController). In the code, a comparison is done using -isKindOfClass. In the debugger, printing descriptions and everything says this variable is an ECSlidingViewController. However, when the code is running, it returns NO.

Currently I have my podfile linking the libraries with both the main target and the test target. If I don't do this, the test target can't find the libraries.

This answer solved it for me https://stackoverflow.com/a/27165120/2777364 .

In short you should not link pod with your test target and you should create separate linking with at least one other pod for test target to force generating configuration set.

target 'MainTarget' do
    pod 'PodYouTryToTest'
end

target 'Tests' do
    pod 'AtLeastOneOtherPod'
end

Answer above is "The Right Way" of solving this. As a quick workaround I can propose a method:

Class getBundleDependentClass(Class class) { 
     return NSClassFromString(NSStringFromClass(class)); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM