Run logic tests in Xcode 4 without launching the simulator Run logic tests in Xcode 4 without launching the simulator xcode xcode

Run logic tests in Xcode 4 without launching the simulator


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 to YES

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 simply return.

Update: I have changed my approach. See How to Easily Switch Your App Delegate for Testing.


In the last xcode version (5.0.2) you can do this in very easy way. Choose your Test target, "General" tab. Set "None" in field "Target". Then tap on "Build phases" tab and remove your Main target from "Target dependencies".


In your situation, I am assuming that you have a separate Logic Tests and Application Tests target (if not - you need to). In your schemes configuration you define which targets are built for the 'Test' scheme. If your application tests are not running, the simulator will not launch.

I suspect that you might be trying to run 'logic tests' in an 'Application tests' target (such as the one created by default by Xcode). See more about this difference here (and how to set ut up).