Don't launch simulator when running unittests Don't launch simulator when running unittests xcode xcode

Don't launch simulator when running unittests


Using xCode 7 and xCtool.

xctool is capable of executing unit tests without the simulator.

To get this working,

1 . Update target settings to run without a host app.

Select your project --> then test target --> Set the host application to none.

enter image description here

2. Install xctool , if you don't have it.

brew install xctool

3. Run the tests using terminal with xctool.

xctool -workspace yourWorkspace.xcworkspace -scheme yourScheme run-tests -sdk iphonesimulator


You can create a Mac OSX Unit Test instead of an iOS unit test. This requires that you not include any iOS specific libraries in the unit tests though. You can do this via the following:

  1. Select the project -> the target drop down -> "Add Target..."
  2. Select "Mac OSX" -> "Other" -> "Cocoa Unit Testing Bundle"
  3. Create the testing bundle as you would a normal project

You can now add sources to the unit test and run it like an iOS test without launching the simulator.


I've asked the same question to apple engineers. Unfortunately it doesn't seem you can accomplish this and stay with iOS at the same time. There are some tricks you can do to check if testing. You could put this code snippet in your AppDelegate.h or some other global class to say not load a root viewcontroller and prevent any wierdo ui stuff from corrupting your unit tests:

static BOOL isTesting() {    BOOL isTesting = !isEmpty([[[NSProcessInfo processInfo] environment] objectForKey:@"XCInjectBundle"]);    return isTesting;}

I've also had an apple engineer verify this is a legitimate check. And to give credit where credit is due, this is from: Programmatically determine current target (run or test) in iOS project

EDIT:I've also had success with this and it's a little more straight forward:

static BOOL isTesting() {    return [[[NSProcessInfo processInfo] processName] isEqualToString:@"xctest"];}