Why skipping the regular launch sequence when testing using an alternative application delegate can be useful ?
You can find your own answer, in my case: speed! and because i want to be able to test host application APIs (to run tests in iPhone environment and test Xib loading and other things) but without all the usual launch sequence.
But what launch sequence i want to avoid?
-> The normal app delegate (and eventually application:didFinishLaunchingWithOptions)
It depends on your app, but it’s not unusual for it to doing things like:
- Set up all your default data if missing (with Core Data/NSUserDefaults/NSUbiquitousKeyValueStore/Realm/[write yours here])
- If there is some stored data reconfigure necessary things, like scheduled local notifications
- Check network reachability
- Configure the root view controller (in our case if it’s the first time there appears a wizard)
- Retrieve from a server some configuration
- … N tasks
Can be a lot of things to do before we even start testing.
So, if all we want is to run our tests, why not avoid all that things?
Lets skip it and use an alternative application delegate to speed up the testing process.
The trick here is to create a new class for example: “QNTestingAppDelegate” and put it in the testing target, but only in the testing target.
An then in our “main”, if the class is available, lets use it :
Our “QNTestingAppDelegate” Looks like: QNTestingAppDelegate.h
And that’s all folks.