Created
September 13, 2014 19:52
-
-
Save idStar/40c57e1c5af4c44fd129 to your computer and use it in GitHub Desktop.
A way to exit full app launch mechanics when you're simply invoking the XCTest target and want to speed things up.
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
#pragma mark - XCTest Support | |
static BOOL isRunningTests(void) __attribute__((const)); | |
/** | |
We need a mechanism to detect if we have been invoked / are running from a unit test. | |
If we are, we'll want to exit early instead of doing all kinds of view controller setup. | |
This function determines based on the environment, if we're running in a unit test process, | |
such as XCTest. | |
*/ | |
static BOOL isRunningTests(void) | |
{ | |
NSDictionary *environment = [[NSProcessInfo processInfo] environment]; | |
NSString *injectBundle = environment[@"XCInjectBundle"]; | |
return [[injectBundle pathExtension] isEqualToString:@"xctest"]; | |
} | |
#pragma mark - App Lifecycle | |
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
// If running XCTest unit tests, exit early to get back to the test runner | |
if (isRunningTests()) { return YES; } | |
// Anything else you might want to do at this stage. | |
return YES; | |
} | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
// If running XCTest unit tests, exit early to get back to the test runner | |
if (isRunningTests()) { return YES; } | |
// Anything else you might want to do at this stage. | |
return YES; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment