Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCUnit: How to run tests without launching iPhone simulator?

I'm following iOS Development Guide: Unit Testing Applications. However, when I attempt to build (Command+B) the LogicTests target (step 8 of "Setting Up Logic Testing"), I get the error: "The selected run destination is not valid for this action."

Since I added my application target to LogicTests's target dependencies, I'm able to run the unit tests with Command+U, but this also launches the iPhone Simulator.

To save time & resources, is it possible to run the OCUnit tests (both logic & application tests) without launching the iPhone Simulator?

like image 551
ma11hew28 Avatar asked Dec 07 '22 21:12

ma11hew28


2 Answers

I understand the annoyance of the simulator popping up in unit tests. The best remedy I've been able to find is to do Command + U, followed by Command + H when launching unit tests. (Control + H hides the simulator after it appears.) Since it appears nearly instantaneously, this can be an effective way of getting it out of your range of vision.

like image 189
markshiz Avatar answered Jan 19 '23 01:01

markshiz


I've managed to run my unit tests which test my model classes without the simulator being launched as follows:

  1. I didn't set any bundle loader or test host build settings, instead I just added the .m files I was unit testing to the Build Phases Compile Sources.

  2. I then ran the unit tests from the command line using:

    xcodebuild -verbose -target TheElementsUnitTests -configuration Debug -sdk iphonesimulator5.0 clean build
    

Not really sure why this didn't launch the simulator, but it definitely didn't!

like image 26
MandyW Avatar answered Jan 19 '23 01:01

MandyW