Xcode: TEST vs DEBUG preprocessor macros

后端 未结 11 899
余生分开走
余生分开走 2020-11-28 06:24

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

11条回答
  •  一生所求
    2020-11-28 06:46

    Modified version of Kev's answer that works for me on Xcode 8.3.2

    +(BOOL)isUnitTest {
    
        static BOOL runningTests;
        static dispatch_once_t onceToken;
    
        // Only check once
        dispatch_once(&onceToken, ^{
            NSDictionary* environment = [[NSProcessInfo processInfo] environment];
            if (environment[@"XCTestConfigurationFilePath"] != nil && ((NSString *)environment[@"XCTestConfigurationFilePath"]).length > 0) {
                runningTests = true;
            } else {
                runningTests = false;
            }
        });
        return runningTests;
    }
    

提交回复
热议问题