Created
December 7, 2012 21:32
-
-
Save markschabacker/4236703 to your computer and use it in GitHub Desktop.
Xcode 4.5 Command Line Unit Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run iOS Unit Tests from the command line with Xcode 4.5 and iOS 6 | |
# Adapted from Scott Thompson at http://stackoverflow.com/a/10823483/1359212 | |
# | |
# Steps: | |
# 1. Create a new Xcode Scheme for the Tests target | |
# 2. Edit the Tests Scheme so that the "Run" checkbox is checked for the Tests target | |
# 3. Use this script as the Test Target's "Run Script" entry on the "Build Phases" tab | |
# 4. Run tests from the command line with: | |
# xcodebuild -sdk iphonesimulator -scheme 'TestSchemeName' build SL_RUN_UNIT_TESTS=YES | |
if ENV['SL_RUN_UNIT_TESTS'] then | |
launcher_path = "ios-sim" #File.join(ENV['SRCROOT'], "Scripts", "ios-sim") | |
test_bundle_path= File.join(ENV['BUILT_PRODUCTS_DIR'], "#{ENV['PRODUCT_NAME']}.#{ENV['WRAPPER_EXTENSION']}") | |
environment = { | |
'DYLD_INSERT_LIBRARIES' => "/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection", | |
'XCInjectBundle' => test_bundle_path, | |
'XCInjectBundleInto' => ENV["TEST_HOST"] | |
} | |
environment_args = environment.collect { |key, value| "--setenv #{key}=\"#{value}\""}.join(" ") | |
app_test_host = File.dirname(ENV["TEST_HOST"]) | |
out_file = File.join(ENV['BUILT_PRODUCTS_DIR'], 'ios_sim.out') | |
system("#{launcher_path} launch \"#{app_test_host}\" #{environment_args} --args -SenTest All #{test_bundle_path} > #{out_file} 2>&1") | |
# cat the output for vim quickfix | |
system("cat #{out_file}") | |
grep_result = %x[grep -c ": error:" #{out_file}] | |
if "0\n" != grep_result | |
abort('test failure') | |
end | |
else | |
puts "SL_RUN_UNIT_TESTS not set - Did not run unit tests!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment