iOS application unit tests from the command line: Xcode 4.5 updateBy Mark on November 11th, 2012 in Technobabble
Tags: iOS, unit testing, xcode, xcode4
We receive a decent amount of traffic from a post I wrote 18 months ago in which we described how to trick Xcode 4.x into running your application unit tests from the command line.
Unfortunately, as of Xcode 4.5, this trick appears to be broken. You’ll get this error message when you run your tests:
Unknown Device Type. Using UIUserInterfaceIdiomPad based on screen size
Terminating since there is no workspace.
(For more details, see this StackOverflow post regarding Xcode 4.5 command line unit testing.)
Worse yet, if you’re like us and using command line unit testing in a CI (=Jenkins) environment, you probably didn’t even notice the failure at first, because the
xcodebuild command doesn’t fail — it completes successfully despite not running any of your tests (!).
Luckily, a gentleman named Scott Thompson on StackOverflow had found a way a few months prior (even to Xcode 4.5) to use
ios-sim to launch the iOS simulator with some arguments and environment variables to tell the simulator to running application unit tests, much in the way Xcode magically does when you press Command-U in the IDE.
The solution involves creating a new scheme for your tests, and then using a post-build script to run
ios-sim with the right flags. There’s no point to reproduce the solution here, as the SO answer is well-written and clear:
Best of luck, and thanks Scott and Pawel!