Simulator fails after a previous test run

The first run is fine, but the next test run on the same simulator fails or hangs — state from the previous run leaked into this one.

Strong fit Likely class: stale device state between runs · Updated

Symptom

A run works once. The next run against the same simulator behaves differently — it hangs, fails to launch, or errors in a way the first run did not. Something from the previous run is still around.

What it usually looks like

Why it happens / likely failure classes

The simulator carries state forward, and incomplete teardown leaves it dirty:

Quick checks

# After a run, what state is the device left in?
xcrun simctl list devices | grep -i 'boot\|shutting'

# Anything left running that belongs to the previous run?
pgrep -lf 'YourAppName|XCTest|testmanagerd'

# Does a clean erase between runs make the second run reliable?
xcrun simctl shutdown <UDID>; xcrun simctl erase <UDID>

If erasing between runs reliably fixes the second run, you have a state-leak problem, not a test bug.

Manual mitigations

When XCSteward may help

Starting each run from a known, clean state is central to XCSteward’s design:

A strong candidate to test against this class of failure.

When XCSteward probably will not help

Common questions

What does "Simulator fails after a previous test run" usually mean?
It usually points to stale device state between runs. The first run is fine, but the next test run on the same simulator fails or hangs — state from the previous run leaked into this one. Start by checking simulator readiness, destination selection, CoreSimulator/simctl responsiveness, and whether another xcodebuild, simctl, or Simulator process is already active before treating it as a test-code failure.
Can XCSteward help with "Simulator fails after a previous test run"?
This is a strong fit when the failure is operational: simulator readiness, destination resolution, CoreSimulator responsiveness, cleanup, timeouts, or local concurrency. XCSteward may help by making those phases bounded, serialized, and easier to inspect. It will not fix broken tests, code signing, missing runtimes, or vendor image bugs.
What should I check first?
Check whether xcrun simctl commands return promptly, whether xcodebuild can resolve a concrete simulator destination, whether the device is truly ready rather than merely Booted, and whether concurrent agents, scripts, or manual runs are touching the same simulator subsystem.