Skip to content

Instantly share code, notes, and snippets.

@Tulakshana
Created November 19, 2024 23:41
Show Gist options
  • Save Tulakshana/b73eb38c0b68746e72aa1a1356b32128 to your computer and use it in GitHub Desktop.
Save Tulakshana/b73eb38c0b68746e72aa1a1356b32128 to your computer and use it in GitHub Desktop.
Script to run unit tests using xcodebuild. The simulator is configured and launched prior to test execution.
echo "**********************************"
echo "* Create sim if needed *"
echo "**********************************"
test_device_id=$(xcrun simctl list devices | grep "circleci-test-device" | sed 's/ *circleci-test-device *(//' | sed 's/).*//')
if [ -z "$test_device_id" ]; then
echo "Creating test device"
runtime=$(xcrun simctl list runtimes iOS | sed 's/iOS //' | sort -h | tail -1 | sed 's/.* - //' | tr -d '[:space:]')
devicetype=$(xcrun simctl list devicetypes "iPhone " | sort | tail -1 | sed 's/.*(//' | sed 's/).*//' | tr -d '[:space:]')
test_device_id=$(xcrun simctl create "circleci-test-device" "$devicetype" "$runtime" | tr -d '[:space:]')
fi
echo "test_device_id: $test_device_id"
echo "**********************************"
echo "* Boot sim if needed *"
echo "**********************************"
xcrun simctl list devices "$test_device_id" | grep -q Booted
if [ $? -eq 1 ]; then
echo "Booting $test_device_id"
xcrun simctl boot "$test_device_id"
fi
echo "**********************************"
echo "* Test *"
echo "**********************************"
xcodebuild test \
-quiet \
-scheme "XCODE_UNIT_TEST_SCHEME" \
-workspace "XCODE_WORKSPACE" \
-destination "id=$test_device_id" \
-jobs 1 \
-parallel-testing-enabled NO \
-sdk iphonesimulator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment