When creating a new project with unit tests, Xcode sets the build configuration to Debug for the Test scheme (same for the Run scheme).
Should I differentiate betwee
Preprocessor macros will not work, you need to check the environment at runtime.
Objective-c
static BOOL isRunningTests(void)
{
NSDictionary* environment = [[NSProcessInfo processInfo] environment];
return (environment[@"XCTestConfigurationFilePath"] != nil);
}
Swift
var unitTesting : Bool
{
return ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] != nil
}
(Updated for Xcode 11)