Running tests from the command line
Every command here ran on 16 October 2026 with Xcode 27.1 (27A9275) and the iOS 27.1 runtime (24A94425), unless the text says otherwise. Flags come from man xcodebuild and xcrun xcresulttool help in Xcode 27.1.
Set this once per shell, or put it in front of each command:
export DEVELOPER_DIR=/Applications/Xcode-27.1.app/Contents/DeveloperPick and boot the simulator
Reuse the "iPhone Duo" simulator that is already on the Mac. Find its UDID and boot it:
xcrun simctl list devices available | grep "iPhone Duo"
xcrun simctl bootstatus <UDID> -b- Don't create a simulator for tests. Each one takes about 4-6 GB of disk once it has booted (measured on 18 October: the shared "iPhone Duo" on our Mac took 3.9 GB). If none is listed,
duo-setupstep 3 creates one after the user agrees, and every later run reuses it. - Measured: a newly created iPhone Duo simulator made
xcodebuild testfail with "Timed out trying to boot simulator after waiting 60.00s" and exit 65.bootstatus -bthen booted it in about a minute, and the same tests ran. Boot first, in the background if you can't wait. - Address the simulator with
-destination "id=<UDID>": two simulators can share a name. Measured:-destination "platform=iOS Simulator,name=iPhone Duo"resolved and built. - A UI test brings the app to the front of that simulator, and each
launch()ends any running copy first (XCUIAutomation header). Tell the user before a run on their simulator. If another agent or script is driving it, wait until it is done. - Measured: a new Duo simulator boots closed (the hinge reported
closed, window 466 × 678 pt). Poses change only in Device Hub.
A dedicated simulator (opt-in)
Only when the user asks for a separate test simulator. Warn them first that it takes about 4-6 GB of disk. Create it, run the tests, and delete it in the same session, even when a test fails:
UDID=$(xcrun simctl create "Tests Duo" com.apple.CoreSimulator.SimDeviceType.iPhone-Duo com.apple.CoreSimulator.SimRuntime.iOS-27-1)
xcrun simctl bootstatus "$UDID" -b
# ... run tests with -destination "id=$UDID" ...
xcrun simctl shutdown "$UDID"; xcrun simctl delete "$UDID"- Delete only the simulator you created, by the UDID
createprinted. Never delete or erase one you didn't create. - The runner script below does all of this with
CREATE_SIMULATOR=1, and deletes the simulator when it exits. - Measured: the iOS 27.1 runtime refused other iPhones:
simctl createwith iPhone 17, 17e, 17 Pro, Air, 18 Pro or 18 Pro Max failed with "Incompatible device". To run the same suite on another iPhone, use the iOS 27.0 runtime and a deployment target of 27.0 or lower (an iPhone 17 Pro on iOS 27.0 worked).
Run the tests
rm -rf build/UITests.xcresult
xcodebuild test \
-project App.xcodeproj -scheme App \
-destination "id=$UDID" \
-parallel-testing-enabled NO \
-derivedDataPath build/DerivedData \
-resultBundlePath build/UITests.xcresult \
-collect-test-diagnostics never| Flag | Why |
|---|---|
-destination |
id=<UDID> of the iPhone Duo simulator. platform=iOS Simulator,name=iPhone Duo,OS=27.1 also works, but two simulators can share a name. |
-parallel-testing-enabled NO |
Overrides the scheme's parallel setting (man xcodebuild). With parallel testing on, xcodebuild runs the tests on a clone of the simulator, not the one you named, and each clone is one more simulator on disk. duo-shared-screen measured this: "Clone 1 of iPhone Duo", which started closed. A clone starts in its own pose, not the one you set in Device Hub. It boots fresh, which the two-player recipe's runner says can take minutes. And a manual fold test then waits on a device nobody is looking at. Its log lines also change to Test case '...' passed on 'Clone 1 of ...', which the greps on this page don't match. Always pass NO for Duo runs. |
-derivedDataPath build/DerivedData |
Keeps build products next to the project, so later commands can find the .xctestrun file. |
-resultBundlePath |
Writes an .xcresult bundle. The man page says xcodebuild exits with an error if the path already exists, so delete it first. |
-collect-test-diagnostics never |
Skips sysdiagnoses and log archives on failure. See "Sitting after the last test". |
-only-testing:Target/Class/method |
Runs one target, class or method. Repeat it for several. -skip-testing: does the reverse. |
-test-iterations N with -retry-tests-on-failure or -run-tests-until-failure |
Hunts flaky tests. |
-enumerate-tests |
Lists the tests a run would execute, without running them. |
Test identifiers follow TestTarget/TestClass/testMethod (Running tests and interpreting results). Measured: -only-testing:DuoSampleUITests/BoardUITests/testTapInsideAShape worked without parentheses; the result bundle then names the test BoardUITests/testTapInsideAShape(), with them.
Exit codes, measured: 0 when all tests pass; 65 when a test fails, and also when the run can't start (the boot timeout above).
Build once, test many times
xcodebuild build-for-testing -project App.xcodeproj -scheme App \
-destination "id=$UDID" -derivedDataPath build/DerivedData
# Same scheme, no rebuild:
xcodebuild test-without-building -project App.xcodeproj -scheme App \
-destination "id=$UDID" -parallel-testing-enabled NO -derivedDataPath build/DerivedData \
-resultBundlePath build/Run2.xcresult -collect-test-diagnostics never
# Or point at the .xctestrun file that build-for-testing wrote (no -project then):
xcodebuild test-without-building \
-xctestrun build/DerivedData/Build/Products/App_iphonesimulator27.1-arm64.xctestrun \
-destination "id=$UDID" -parallel-testing-enabled NO -resultBundlePath build/Run3.xcresult \
-collect-test-diagnostics never -only-testing:AppUITests/BoardUITests/testDragPieceIntoSlotMeasured: all three forms ran (on 16 October, without -parallel-testing-enabled NO; the sample's scheme doesn't turn on parallel testing, so it made no difference there). The .xctestrun file name carries the SDK and the architectures built; list build/DerivedData/Build/Products/ to find it. Building for -destination "generic/platform=iOS Simulator" named it App_iphonesimulator27.1-arm64-x86_64.xctestrun.
Sitting after the last test
A shipped Duo app's notes said xcodebuild could sit for minutes after the last test while it saved results. We reproduced it and found the cause:
| Run | Last test ended | xcodebuild exited | Result bundle |
|---|---|---|---|
| 4 passing tests, default flags | 21:10:19 | 21:10:19 | 320 KB |
| 1 failing test, default flags | 21:10:57 | 21:20:57, right after the log line "Failure collecting diagnostics from simulator: Timed out after 600.0 seconds" | 50 MB |
1 failing test, -collect-test-diagnostics never |
21:22:18 | 21:22:18 | 1.1 MB |
So pass -collect-test-diagnostics never for agent and CI runs. Turn it back on (on-failure) only when you need a sysdiagnose to debug a crash. Each Test Case ... passed or failed line reaches the log before that wait (only the ** TEST FAILED ** or ** TEST EXECUTE FAILED ** line comes after it), so a script can read results without waiting for the process.
Run in the background and poll
UI test runs take minutes. An agent should start the run in the background, write the log to a file, and check it:
( xcodebuild test ... -collect-test-diagnostics never > build/ui-tests.log 2>&1; echo "EXIT $?" >> build/ui-tests.log ) &
# later:
grep -E "^Test Case .*(passed|failed)|\*\* TEST|^EXIT" build/ui-tests.log- The last line marks the end:
** TEST SUCCEEDED **or** TEST FAILED **fortest, and** TEST EXECUTE SUCCEEDED **or** TEST EXECUTE FAILED **fortest-without-building(measured). Match\*\* TEST, as the grep above does; a literalTEST FAILEDmisses theEXECUTEform. - Each test prints
Test Case '-[Target.Class testName]' passed (N seconds)orfailed. - A failed assertion prints
path/File.swift:LINE: error: -[Target.Class testName] : message.
Read the result bundle
xcrun xcresulttool get test-results summary --path build/UITests.xcresult # totals + every failure
xcrun xcresulttool get test-results tests --path build/UITests.xcresult # the test tree with results
xcrun xcresulttool get test-results activities --path build/UITests.xcresult \
--test-id "BoardUITests/testTapInsideAShape()" # each tap, wait and query
xcrun xcresulttool export attachments --path build/UITests.xcresult --output-path build/attachments- The summary is JSON. Its
resultisPassedorFailed;testFailureslists each failure withtestIdentifierStringandfailureText(measured). export attachmentswrites the files plus amanifest.jsonnaming each one. Measured: a failing UI test came with a screen recording (.mp4) and a "Synthesized Event" attachment without any code; screenshots added intearDownwere skipped by--only-failures.- Open the bundle in Xcode to see the same report with screenshots (Running tests and interpreting results).
xcrun xcresulttool helpmarksget objectandgraphas deprecated; useget test-results.
A runner script
Tools/run-ui-tests.sh. Measured (16 October): on a private iPhone Duo simulator it printed each test line, then Passed | passed 2 | failed 0 | skipped 0 and exited 0; with a broken assertion it printed the FAIL line with the message and exited 65. On 18 October it changed to reuse the existing iPhone Duo by default, with a dedicated simulator only on request. That version passed zsh -n. Its find step picked the shared "iPhone Duo" on our Mac, and stopped with the setup hint when the list had no Duo. With stand-in xcrun and xcodebuild commands, CREATE_SIMULATOR=1 deleted the simulator it made, by its UDID, after a failing run. The full UI run was not repeated, and no real simulator was created.
#!/bin/zsh
# Runs the UI tests on the iPhone Duo simulator, then prints the result summary.
# Tools/run-ui-tests.sh all UI tests
# Tools/run-ui-tests.sh -only-testing:AppUITests/BoardUITests
# Settings: PROJECT, SCHEME, DEVICE_ID (a UDID). Without DEVICE_ID it reuses the existing
# iOS 27 simulator named "iPhone Duo" (or another iPhone Duo), booted ones first.
# It never creates a simulator unless you set CREATE_SIMULATOR=1. Then it makes a
# dedicated one (about 4-6 GB of disk) and deletes it when the run ends.
# A UI test brings the app to the front of the simulator it runs on.
set -euo pipefail
cd "$(dirname "$0")/.."
export DEVELOPER_DIR="${DEVELOPER_DIR:-/Applications/Xcode-27.1.app/Contents/Developer}"
PROJECT="${PROJECT:-App.xcodeproj}"
SCHEME="${SCHEME:-App}"
RESULT="build/UITests.xcresult"
LOG="build/ui-tests.log"
if [[ -n "${DEVICE_ID:-}" ]]; then
:
elif [[ "${CREATE_SIMULATOR:-0}" == 1 ]]; then
echo "Creating a dedicated iPhone Duo simulator (about 4-6 GB of disk). It is deleted when this run ends." >&2
DEVICE_ID=$(xcrun simctl create "Tests Duo" com.apple.CoreSimulator.SimDeviceType.iPhone-Duo \
com.apple.CoreSimulator.SimRuntime.iOS-27-1) || { echo "Could not create an iPhone Duo simulator. See duo-setup." >&2; exit 1; }
trap 'xcrun simctl shutdown "$DEVICE_ID" > /dev/null 2>&1; xcrun simctl delete "$DEVICE_ID"' EXIT
else
DEVICE_ID=$(xcrun simctl list --json devices available | python3 -I -c '
import json, sys
found = [(d["name"] == "iPhone Duo", d["state"] == "Booted", d["udid"])
for runtime, devices in json.load(sys.stdin)["devices"].items() if "iOS-27" in runtime
for d in devices if d.get("deviceTypeIdentifier", "").endswith("iPhone-Duo")]
print(max(found)[2] if found else "")')
if [[ -z "$DEVICE_ID" ]]; then
echo "No iPhone Duo simulator found. Create one with duo-setup (step 3), or set DEVICE_ID." >&2
echo "For a throwaway one, rerun with CREATE_SIMULATOR=1 (about 4-6 GB, deleted after the run)." >&2
exit 1
fi
fi
mkdir -p build
xcrun simctl bootstatus "$DEVICE_ID" -b > /dev/null # xcodebuild gives a simulator only 60 s to boot
rm -rf "$RESULT" # xcodebuild refuses an existing result path
# -parallel-testing-enabled NO: otherwise xcodebuild may run the tests on a clone of the
# simulator, which takes more disk, boots fresh and ignores the pose you set in Device Hub.
set +e
xcodebuild test \
-project "$PROJECT" -scheme "$SCHEME" \
-destination "id=$DEVICE_ID" \
-parallel-testing-enabled NO \
-derivedDataPath build/DerivedData \
-resultBundlePath "$RESULT" \
-collect-test-diagnostics never \
"$@" > "$LOG" 2>&1
STATUS=$?
set -e
grep -E "^Test Case .*(passed|failed)|: error: |\*\* TEST" "$LOG" || true
if [[ -d "$RESULT" ]]; then
xcrun xcresulttool get test-results summary --path "$RESULT" --compact | python3 -I -c '
import json, sys
d = json.load(sys.stdin)
print(d["result"], "| passed", d["passedTests"], "| failed", d["failedTests"], "| skipped", d["skippedTests"])
for f in d["testFailures"]:
print("FAIL", f["testIdentifierString"], "-", f["failureText"])'
fi
exit $STATUSPass test settings through to the runner with TEST_RUNNER_ variables: TEST_RUNNER_DUO_MANUAL_FOLD=1 Tools/run-ui-tests.sh sets DUO_MANUAL_FOLD=1 inside the test process (man xcodebuild, Xcode 27.1).
Logic tests
Tools/run-logic-tests.sh # swiftc script, see logic-tests.md
(cd AppCore && xcrun swift test) # Swift package with Swift TestingBoth run on the Mac, need no simulator, and exit non-zero on failure.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| "Timed out trying to boot simulator after waiting 60.00s" | First boot of a new simulator is slow | xcrun simctl bootstatus <UDID> -b first |
| xcodebuild exits at once with an error about the result path | The .xcresult path exists |
rm -rf it first, or use a new name per run |
| xcodebuild sits about 10 minutes after a failure | Diagnostics collection timing out | -collect-test-diagnostics never |
"Incompatible device" from simctl create |
The iOS 27.1 runtime took only the iPhone Duo in our tries | Use iOS 27.0 for other iPhones |
| A test passes alone and fails in the suite | State left by an earlier test | Launch every test with -resetState |
Unable to find a destination matching ... |
Wrong name, or no runtime for the deployment target | xcodebuild -showdestinations -scheme App |
| Taps or drags do nothing | Points computed from app.frame |
Use element coordinates (ui-tests.md) |
| Rotation in a test does nothing on the Duo | XCUIDevice.shared.orientation didn't rotate the app (measured, closed) |
Rotate in Device Hub |
| Wrong Xcode used | DEVELOPER_DIR missing |
Export it; never sudo xcode-select (duo-setup) |