I\'m running into a strange problem that I haven\'t run into before.
When you do cmd+U to run your Unit Tests (OCUnit for example) does it actually call the main.m,
Excellent answers above that suggest dynamically changing the application delegate at run time.
The small modification I make is to detect a unit test run by querying NSProcessInfo
. The advantage is that you don't need to have a class that can be detected to see if unit tests are running.
int main(int argc, char * argv[])
{
// Put your App delegate class here.
const Class appDelegateClass = [ATAppDelegate class];
NSDictionary *const environmentDictionary =
[[NSProcessInfo processInfo] environment];
const BOOL runningUnitTests =
environmentDictionary[@"XCInjectBundleInto"] != nil;
NSString *delegateName =
runningUnitTests ? nil : NSStringFromClass(appDelegateClass);
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, delegateName);
}
}
The @"XCInjectBundleInto"
property in environmentDictionary
is the path to your unit tests bundle and is set up by Xcode.