This is a more reliable method of determining whether or not your code is currently running inside of an XCTestCase than the previously used preprocessor macro method.
XCTest() method defined below to the bottom of your
.pch files (both your application’s
.pch and your test target’s
Then simply call the method to determine whether or not your code is currently running inside of an XCTestCase.
XCTest Method for .pch Files
#define XCTest() ([[NSProcessInfo processInfo] environment][@"XCInjectBundle"] != nil)