Skip to content

Instantly share code, notes, and snippets.

@mbinna
Last active December 18, 2015 07:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbinna/5743674 to your computer and use it in GitHub Desktop.
Save mbinna/5743674 to your computer and use it in GitHub Desktop.
Detect if the app was launched in the iOS Simulator to execute the unit tests. Source: http://www.objc.io/issue-1/testing-view-controllers.html
static BOOL isRunningTests(void) {
NSDictionary *environment = [[NSProcessInfo processInfo] environment];
NSString *injectBundle = environment[@"XCInjectBundle"];
return [[injectBundle pathExtension] isEqualToString:@"octest"];
}
@Legoless
Copy link

Legoless commented Jan 7, 2015

This fails if it is running xctest.

@Gui13
Copy link

Gui13 commented Jan 17, 2015

Well, replace @"octest" by @"xctest and rulez

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment