I'm having issues unit testing code involving an isKindOfClass
check. There are a lot of existing question on this topic and the answers recommend:
-ObjC
is included as an "other linker flag". It is..m
files from the project target are not added to the test target. They aren't.To make sure there weren't odd circumstances, I created a fresh project. I:
"TwistedOakCollapsingFutures"
pod install
-ObjC
is present in both targets[TOCFuture futureWithResult:@1]
to AppDelegate.m
XCTAssert([AppDelegate.makeFuture isKindOfClass:TOCFuture.class], @"")
to the example testBasically I have no idea why this shouldn't work. Even more oddly, if I go counter to existing answers and include AppDelegate.m
in the test target, the test starts to pass.
What is going on? Am I suppose to include the source files in the test target, or am I not supposed to?
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));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With