In general, if you are stuck in an environmental issue where unconditional testing seems impossible, you can get around it if the benefits are large enough to ensure that you jump through some hoops.
The situation here is a special case of unwanted external dependencies, which I usually solve in my unit tests: #ifdefing from tiny bits of dependent code or by injecting stub classes to populate the expected dependency roles sufficient for my code to be tested.
So, in this particular case, you can create a new source file, linked only in a test suite called "UIKitStubClasses.m" ... inside it, you could realize simple needs to simulate dependent UIKit classes, such as UIViewController, your test links and carefully execute your own logic.
It is important to remember that usually this is not always so much. Tests let you know what you need to implement in the stub, for example, throwing exceptions about unimplemented methods. You simply add what you need to calm errors and test your code, and then your stub class will be sufficient for testing, like any legitimate class of system systems.
danielpunkass
source share