Under Xcode 6 / iOS 8 SDK and earlier, I could check the BOOL value of
[NSBundle bundleWithIdentifier:@"com.mycompany.AppUnitTests"] != nil
from inside my app to see if a certain set of unit tests were in progress. (Note that I am running my tests as application tests, not as logic tests.) As of Xcode 7 / iOS 9 SDK that seems to no longer work - the bundle is always returned as nil. I suspect that Xcode 7 has changed the way that apps load and run their unit tests but I can't put my finger on it. Anyone know a way to detect this that works under Xcode 7 / iOS 9 SDK?
(BTW, I know I can check [NSBundle bundleForClass:NSClassFromString(@"XCTest")]
to find out if any set of unit tests are in progress, but I have several test suites and need to be able to differentiate between them; hence checking by bundle ID. Thanks.)
UPDATE:
This change in behavior seems to be due to the change in bundle loading order described here. And, as Apple describes here, +bundleWithIdentifier:
only retrieves a reference to bundles that have already been loaded - hence I could not get a reference to the bundle that way when it had not yet loaded. I guess the question now becomes, how do I get the test bundle to load before the app starts?