Faster test cycles without app delegate for your unit tests with Swift in XCode

We build professional apps for Android, iOS and mobile web.
Have a look

Unit testing should be as easy as possible and anything that slows you down should be removed.

One thing that makes unit testing slow for larger apps is that the unit tests start the app in the simulator and load the app delegate. Usually, this will initialize all sorts of things which you don't need for your unit test. I don't need to initialise the main controller, analytics etc. I just want to run a unit test which should be very self-contained and I want to control the context. This is why I don't want the app delegate to start when I unit test.

I spent heaps of time trying to switch out the app delegate at runtime when in testing mode. But there is a very simple solution.

I found a solution on stackoverflow that works with Swift and Xcode 7. This solution on stackoverflow works great for me.

  • I am using a separate scheme for the unit test.
  • Important: In your test target -> General -> Testing : set Host Application to None xcode image
  • When running your unit test just switch to the Test Scheme and run your unit test (Command-U).

It's great as no app gets launched and your unit tests run super fast without any baggage.