Programmatically determine current target (run or test) in iOS project
None of these answers really helped me. I wanted my app to know when I was running tests for the sole purpose of limiting the logging in my test targets. The tests run faster when I'm not logging a bunch of stuff. So, I did it by adding a custom argument to the test portion of my scheme:
In my application code, I can now check if I am testing or not:
- (void)logError:(NSError*)error{ if([[[NSProcessInfo processInfo] arguments] containsObject:@"-FNTesting"]) return; NSLog(@"LOG THE ERROR");}
Thanks to @cameronspickert for being one of the only places I could actually find how to use the custom argument
http://cameronspickert.com/2014/02/18/custom-launch-arguments-and-environment-variables.html