Created
January 15, 2014 14:03
-
-
Save rsaunders100/8436798 to your computer and use it in GitHub Desktop.
To prevent application logic from interfering with unit tests.
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
static BOOL isRunningTests(void) __attribute__((const)); | |
- (BOOL)application:(UIApplication *)application | |
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
if (isRunningTests()) { | |
return YES; | |
} | |
// | |
// Normal logic goes here | |
// | |
return YES; | |
} | |
static BOOL isRunningTests(void) | |
{ | |
NSDictionary* environment = [[NSProcessInfo processInfo] environment]; | |
NSString* injectBundle = environment[@"XCInjectBundle"]; | |
NSString* pathExtension = [injectBundle pathExtension]; | |
return ([pathExtension isEqualToString:@"octest"] || | |
[pathExtension isEqualToString:@"xctest"]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a modified version of the snippet from this excellent article:
http://www.objc.io/issue-1/testing-view-controllers.html
I added compatibility for XCode5's newer XCTest framework.
This is also mentioned in my blog post:
http://www.rsaunders.co.uk/2014/01/preventing-unit-tests-from-crashing.html