Skip to content

Instantly share code, notes, and snippets.

@SQiShER
Last active December 13, 2015 23:19
Show Gist options
  • Save SQiShER/4990624 to your computer and use it in GitHub Desktop.
Save SQiShER/4990624 to your computer and use it in GitHub Desktop.
The bumpy road to iOS Command-Line builds. A step-by-step guide. (Work in progress)
  • Configure a new (shared) Scheme to run tests during the build phase

  • Install ios-sim via Homebrew

      brew install ios-sim
    
  • Run ios-sim from a script in the test target

      RUN_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 command

      xcodebuild -sdk iphonesimulator -arch i386 -workspace <name of your workspace>.xcworkspace -scheme <name of your test scheme> clean build
    

Additional Resources

Once you are ready to go, you may want to take a look at the following projects:

@SQiShER
Copy link
Author

SQiShER commented Feb 19, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment