Please can someone tell me how to have the test harness not instantiate the whole app? My app is event driven, and it sends a bunch of events through when it starts up that mess with my tests.
I use Xcode 4’s built-in testing. App instantiation may seem like a pain, but as I write on Xcode Unit Testing: The Good, the Bad, the Ugly, it makes it possible to write tests without distinguishing between logic tests and application tests. Specifically, it lets me write unit tests for view controllers.
Here’s what I do to avoid my full startup sequence:
Edit the scheme
- Select the Test action
- In “Test” select the Arguments tab
- Disable “Use the Run action’s options”
- Add an environment variable, setting
runningTests
toYES
Edit your app delegate
-
Add the following to
-application:didFinishLaunchingWithOptions:
as soon as it makes sense to:#if DEBUG if (getenv("runningTests")) return YES; #endif
-
Do the same for
-applicationDidBecomeActive:
but simplyreturn
.
Update: I have changed my approach. See How to Easily Switch Your App Delegate for Testing.