Skip to content

Instantly share code, notes, and snippets.

@idStar
Created September 13, 2014 19:52
Show Gist options
  • Save idStar/40c57e1c5af4c44fd129 to your computer and use it in GitHub Desktop.
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.
#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