Created
June 5, 2015 16:24
-
-
Save netbe/ae90ccf3ab5e4ec65f0c to your computer and use it in GitHub Desktop.
AppDelegate Testing ObjC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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