GHUnit runs in Simulator but not on iPhone
So I have been playing with GHUnit today, and have some nice tests which run just fine in the similator in XCode4. When I run them on the iPhone itself I get the following error:
'Unable to instantiate the UIApplication delegate instance.
No class named GHUnitIPhoneAppDelegate is loaded.'
Before you ask, yes I have the linker options -ObjC
and -all_l开发者_StackOverflowoad
set, and as I said, it works fine in the simulator, so why not the iPhone itself?
Puzzled!
I am not sure to have the real reason of this problem but I did find a workaround.
For a reason I am still not quite sure to understand replacing:
int retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIPhoneAppDelegate");
by
int retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIOSAppDelegate");
in the main file will fix the problem.
The class GHUnitIPhoneAppDelegate
inherits from GHUnitIOSAppDelegate
but it is not included in the final binary (I ran a nm -a GHUnitIPhoneAppDelegate|grep IPhoneApp
with no result).
A wild guess is that since the class only inherits from it (no additional methods or attributes) and because nowhere in the framework this class is instantiated (only mentioned through a string), the compiler, to save space, removes it from the binary information in iOS mode.
Hope this helps, at least that worked for me.
Just to clarify, GHUnitIOS-0.4.32 uploaded on 8/11/2011 to https://github.com/gabriel/gh-unit/downloads throws
NSInternalInconsistencyException', reason: 'Unable to instantiate the UIApplication delegate instance. No class named GHUnitIPhoneAppDelegate is loaded.'
if int main(int argc, char *argv[])
contains:
int retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIPhoneAppDelegate");
It works for:
int retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIOSAppDelegate");
As GHUnitIOSAppDelegate is missing from that armv6 & armv7 libs. Notice GHUnitIPhoneAppDelegate is in the simulator lib ...
GHUnitIOS.framework$ nm -a -arch i386 GHUnitIOS | grep GHUnitIPhoneAppDelegate
nm: no name list
GHUnitIOS(GHUnitIPhoneAppDelegate.o):
00000084 S _OBJC_CLASS_$_GHUnitIPhoneAppDelegate
00000070 S _OBJC_METACLASS_$_GHUnitIPhoneAppDelegate
00000048 s l_OBJC_CLASS_RO_$_GHUnitIPhoneAppDelegate
00000020 s l_OBJC_METACLASS_RO_$_GHUnitIPhoneAppDelegate
GHUnitIOS.framework$
But not in either of the two devices libs ...
GHUnitIOS.framework$ nm -a -arch armv6 GHUnitIOS | grep GHUnitIPhoneAppDelegate
nm: no name list
GHUnitIOS.framework$
GHUnitIOS.framework$ nm -a -arch armv7 GHUnitIOS | grep GHUnitIPhoneAppDelegate
nm: no name list
GHUnitIOS.framework$
I'll leave @apouche's answer as the accepted one, as this answered my problem and helped me out.
However had a message from gabriel, the developer of GHUnit - saying that this is a bug and that he's made a new release (0.4.32) which fixes this issue.
精彩评论