Test bundle injection should happen before main(), not after

Originator:jon.m.reid
Number:rdar://22101460 Date Originated:31-Jul-2015
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:
 
Summary:
As described in http://qualitycoding.org/app-delegate-for-tests/, I have main() test for the presence of a test-specific application delegate. This is important for bypassing the regular app delegate during testing. This technique fails in Xcode 7 beta 4, presumably because the test bundle is being injected too late.

Steps to Reproduce:
1. Create new project for iOS application.
2. Add a TestingAppDelegate to the test target.
3. Change main to:
int main(int argc, char *argv[])
{
    @autoreleasepool {
        Class appDelegateClass = NSClassFromString(@"TestingAppDelegate");
        if (!appDelegateClass)
            appDelegateClass = [AppDelegate class];
        return UIApplicationMain(argc, argv, nil, NSStringFromClass(appDelegateClass));
    }
}


Expected Results:
Expect appDelegateClass to be AppDelegate during normal runs, TestingAppDelegate during unit testing.

Actual Results:
In Xcode 7 beta 4, appDelegateClass is always AppDelegate, even during testing.

Version:
Xcode 7 beta 4, running on Yosemite 10.10.4 (14E46)

Comments

Fixed! In Xcode 7.3 beta

By jon.m.reid at Jan. 13, 2016, 3:08 a.m. (reply...)

Engineering has provided the following information regarding this issue:

The timing of when the test bundle is loaded is an implementation detail. Depending on this is not supported. You will need to find another mechanism if you want to run different code in your app delegate during testing.

Please know that you can move your TestingAppDelegate to a framework/library that you conditionally load when testing (possibly by using DYLD_INSERT_LIBRARIES).

Developer Bug Reporting Team Apple Worldwide Developer Relations

By jon.m.reid at Sept. 9, 2015, 7:01 p.m. (reply...)

Confirmed in Xcode 7 beta 6.

By abraginsky at Sept. 4, 2015, 7:07 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!