Is there any way to programmatically determine if you are running code in the Test target vs the regular Run target while developing iOS applications?
I have the hack of checking if this variable is nil or not as it is only in my test target but this seems pretty hacky.
[[[NSProcessInfo processInfo] environment] objectForKey:@"XCInjectBundle"]
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With