Skip to content

Instantly share code, notes, and snippets.

@netbe
Created June 5, 2015 16:24
Show Gist options
  • Save netbe/ae90ccf3ab5e4ec65f0c to your computer and use it in GitHub Desktop.
Save netbe/ae90ccf3ab5e4ec65f0c to your computer and use it in GitHub Desktop.
AppDelegate Testing ObjC
// AppDelegate.m
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (isRunningTests()) return YES;
// ...
return YES;
}
BOOL isRunningTests(void)
{
NSDictionary* environment = [[NSProcessInfo processInfo] environment];
NSString* injectBundle = environment[@"XCInjectBundle"];
return [[injectBundle pathExtension] isEqualToString:@"xctest"];
}
- (instancetype)init
{
self = [super init];
if (self) {
if (isRunningTests()){
// This bundle has unit tests injected. Let's not really start the app to avoid interfering with the tests.
id infoDictionary = [[NSBundle mainBundle] infoDictionary];
[infoDictionary setValue:@"UnitTest" forKey:@"UIMainStoryboardFile"];
}
}
return self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment