-
Configure a new (shared) Scheme to run tests during the build phase
-
Install
ios-sim
via Homebrewbrew install ios-sim
-
Run
ios-sim
from a script in the test targetRUN_UNIT_TEST_WITH_IOS_SIM=YES if [ "$RUN_UNIT_TEST_WITH_IOS_SIM" = "YES" ]; then test_bundle_path="$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.$WRAPPER_EXTENSION" ios-sim launch "$(dirname "$TEST_HOST")" \ --setenv DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection \ --setenv XCInjectBundle="$test_bundle_path" \ --setenv XCInjectBundleInto="$TEST_HOST" --args -SenTest All "$test_bundle_path" echo "Finished running tests with ios-sim" else "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests" fi
-
Add some weird shit to the App to support command-line runs
When you try to run the tests, you'll see this error:
Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen size Terminating since there is no workspace.
This can be fixed by adding some code as described in the link above.
-
Install Xcode Command Line Tools
-
Finally, run from the test via
xcodebuild
commandxcodebuild -sdk iphonesimulator -arch i386 -workspace <name of your workspace>.xcworkspace -scheme <name of your test scheme> clean build
Once you are ready to go, you may want to take a look at the following projects:
- gradle-XcodePlugin - Automate your Build from Source Code to Test Flight
- Kiwi - Spec-based Testing
I'm currently using this setup with Xcode 4.5.2. But Apple seems to actively work on making automated testing as difficult as possible and mixes things up a little with every new Xcode release. So be prepared to run into problems, as soon as you dare to install a new version.