Skip to content
CoreMacs
XcodeGuide

Managing iOS simulators in CI: runtimes, simctl and parallel testing

A CI Mac that runs iOS tests needs predictable simulators. This guide covers the simctl lifecycle, installing and pinning runtimes with xcodebuild, parallel testing options, recovering from stuck boots, and keeping disk usage in check on long-lived build machines.

CoreMacs News Desk·Published ·Last verified ·5 min read
A Mac Studio on a dark desk beside a display, keyboard, mouse, tablet on a stand and headphones.

Most iOS pipelines start the same way: a Mac, a recent Xcode, and a test command that quietly assumes a simulator exists. That works until a runtime is missing, a device refuses to boot, or the disk fills up. Details change between Xcode releases, so treat the commands below as a starting point and confirm them with the built-in help on your own machine.

Simulators are devices plus runtimes

A simulator combines a device type, such as a particular iPhone model, with a runtime, the OS version it runs. Apple's Xcode guide treats runtimes as optional components you install and remove separately; the Xcode 16 release notes call them disk images. So a device can outlive its runtime, and deleting a device is not the same as removing a runtime.

xcrun simctl list devices
xcrun simctl list runtimes
xcrun simctl runtime list

Run the last command to see which runtime images are installed, and check its output on your own Xcode version. Apple's WWDC19 session Getting the Most Out of Simulator adds that list has a JSON option for scripts.

The simctl lifecycle

For repeatable jobs, create a dedicated device per run. The same session names xcrun simctl help as the place to start, run alone or followed by a command name. It notes that create prints the new device's identifier for scripts to capture, and recommends full identifiers in automation.

UDID=$(xcrun simctl create ci-iphone com.apple.CoreSimulator.SimDeviceType.iPhone-16 com.apple.CoreSimulator.SimRuntime.iOS-18-2)
xcrun simctl bootstatus "$UDID" -b
xcrun simctl shutdown "$UDID"
xcrun simctl delete "$UDID"

The identifiers are examples; take real ones from xcrun simctl list, and run your tests between the boot and shutdown steps. The bootstatus help text, quoted in a fastlane pull request, says the command monitors a device until it finishes booting and that -b boots it first if needed, a clearer signal than a fixed sleep. To reuse a device instead, NSHipster's simctl overview shows xcrun simctl erase "$UDID" after a shutdown to clear its contents; check xcrun simctl help erase on your version.

Installing runtimes without the Xcode interface

Apple's guide Downloading and installing additional Xcode components describes a command-line route for this: download a component once, then install it on multiple Macs.

xcodebuild -downloadPlatform iOS -exportPath ./SimulatorRuntimes/
xcodebuild -importPlatform ./SimulatorRuntimes/<exported-file>.dmg

The Xcode 16 release notes list export and import as new in that release and add that xcrun simctl runtime add also accepts the exported image. On a fresh machine, Apple's guide says to select Xcode with xcode-select -s, then run xcodebuild -runFirstLaunch, which installs required components such as simctl, before importing. Check the export folder for the real file name before importing; Classmethod's example file is named after the build number.

To pin a version, the Xcode 16.1 release notes introduce -buildVersion, which requests a specific released runtime and accepts a release number or a build number. One trap: Apple's guide once said the option takes an Xcode version. In a developer forum thread about the iOS 18.3.1 runtime, an Apple engineer confirmed that it specifies an OS version and said the documentation would be updated. The current guide describes it as an OS version, as in -buildVersion 18.0, so for iOS 18.3.1 you pass 18.3.1, not your Xcode version.

Store the exported image as a CI artifact rather than downloading it on every machine. Mehmet Baykar's walkthrough notes that Xcode caches downloads under ~/Library/Caches/com.apple.dt.Xcode/Downloads/ and suggests deleting that folder after installation to reclaim space.

Parallel testing

Xcode can split a test run across several test runners at once. Apple's Xcode help explains how tests are divided among runners and says that, for iOS apps, the feature works only when tests run in Simulator. The xcodebuild manual page, here in a community mirror, lists three options:

  • -parallel-testing-enabled takes YES or NO and overrides the per-target setting in the scheme.
  • -parallel-testing-worker-count spawns exactly the number of test runners you give and overrides a maximum if both are set.
  • -maximum-parallel-testing-workers only caps the number of runners.

Confirm them with man xcodebuild for your Xcode version. As a suggestion rather than documented guidance, start with a small fixed count and raise it only while timings improve and memory holds up. Tests that share state, such as a database file or fixed ports, can fail intermittently in parallel.

When a simulator will not boot

Boot problems can come from a device left broken by a cancelled job, a missing runtime, or a machine short on memory. A reasonable escalation path:

  1. Shut everything down with xcrun simctl shutdown all, an alias the WWDC19 session describes.
  2. Erase the affected device with xcrun simctl erase "$UDID".
  3. Delete the device and create a fresh one.
  4. If the runtime looks wrong, check xcrun simctl runtime list and import the image again.

The session also explains that most simctl commands exit with zero on success and a non-zero code on failure, so a CI step can fail fast. Wrap the boot step in a timeout so a stuck device fails the job clearly instead of hanging.

Disk usage and cleanup

Runtimes and old devices accumulate on long-lived machines. Apple's guide notes that Xcode's Components settings show how much storage removing a component would recover; delete unneeded runtimes there. For devices, the usual cleanup is:

xcrun simctl shutdown all
xcrun simctl delete unavailable

The WWDC19 session describes the unavailable alias as finding all simulators that use a runtime that is no longer available. Check xcrun simctl help delete on your Xcode version for what it removes, measure disk usage before and after, and schedule cleanup between jobs, not during them.

Sources

Share