iOS UI testing with AI agents: write, run and fix XCUITests with Claude Code, Codex or Cursor
For iOS UI testing with an AI agent, keep XCUITest as the source of truth. Let the agent write XCTest UI tests against accessibility identifiers. Run only the affected test with xcodebuild test -only-testing: or an MCP tool such as MobileBuildMCP's test_sim, and read failures from the .xcresult bundle. Use agent-driven simulator checks for exploration.
Last updated:
An agent can check a UI change in two very different ways. It can run UI tests: deterministic XCUITest code that lives in your repo and runs in CI. Or it can drive the app itself: tap through the simulator and assert what it sees, with no test code. Both are useful; they answer different questions. This guide covers the test path end to end and shows where the agent-driven tools fit. For the tools that only drive the simulator, see iOS simulator MCP servers compared.
Which approach do you need?
| Goal | Approach | Steps |
|---|---|---|
| A regression test that runs in CI on every PR | Agent writes XCUITest, runs it, reads .xcresult | 1–3 |
| "Did my change break the login flow?" right now | Run the existing UI test for that flow with -only-testing | 2–3 |
| Fix a flaky or "element not found" UI test | Retry flags + accessibility-identifier fixes | 4 |
| Quick check of a new screen without writing a test | Agent-driven check: drive the simulator and assert | 5 |
| Goal-based exploratory testing ("buy the first item") | AI user-test tools | 5 |
Step 1: Have the agent write XCUITests (not Swift Testing)
UI tests use XCTest together with the XCUIAutomation framework. Apple's XCTest page: "Use XCTest in combination with XCUIAutomation to interact with an application's UI and validate user interaction flows", while it recommends Swift Testing "for new unit test development" (XCTest, XCUIAutomation). So tell the agent explicitly: unit tests in Swift Testing, UI tests as XCTestCase subclasses in the UI test target.
What to put in your CLAUDE.md / AGENTS.md for UI tests:
The UI test target name and the scheme, so the agent can build a
-only-testingidentifier (step 2)."Query elements by
accessibilityIdentifier, not by visible text." Identifiers survive copy and localization changes. iOS UI Testability Contract exists precisely because identifiers on the wrong view (a parentVStackinstead of theTextField) cause "element not found" failures.How the app reaches a known state at launch (launch arguments, environment, mocks).
Useful Xcode features the agent can lean on:
UI test recording (Xcode 26): open a test function and click the record button at the edge of the editor; Xcode records your UI interactions as test code (Xcode 26 release notes). Record a happy path yourself, then let the agent add assertions and edge cases.
Xcode 27: a launch-test template that runs across "every combination of orientation, localization, and appearance", a test-plan setting for how app crashes during UI testing are treated (off, warning, failure, fatal failure), and
XCUIVoiceOverServicefor driving VoiceOver from UI tests (Xcode 27 release notes).
Skills that teach agents XCUITest (from their READMEs):
iOS Testing (ioloro): Swift Testing for unit tests, XCUITest for "UI automation, accessibility audits, animation hitch testing", plus an
iostestingCLI and an optional hook.Maestro Mobile Testing Skill: if you write Maestro YAML flows instead of XCUITest; verified against Maestro CLI 2.11.0 per its README. Maestro flows are a second test layer next to XCUITest, not a replacement for it inside Xcode.
Step 2: Run only the tests that matter
Running the whole UI suite after every edit is slow. Give the agent the narrowest command. From the xcodebuild man page (xcodebuild(1), mirror of the Xcode man page):
bash
xcodebuild test \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 17' \
-only-testing:MyAppUITests/LoginUITests/testLoginWithValidCredentials \
-resultBundlePath ./TestResults/login.xcresultTest identifiers have the form
TestTarget[/TestClass[/TestMethod]];-only-testingwins over-skip-testing, and you can pass a response file with@file.-testPlan <name>picks a test plan;-only-test-configurationlimits it to one configuration.build-for-testingonce, thentest-without-buildingfor repeated runs.
Through MCP instead of a shell command:
MobileBuildMCP:
test_sim("Test on iOS sim.") andtest_device, with structured test-result output andextraArgsfor flags such as-only-testing(tool manifests). Note: both are markedhideWhenXcodeAgentMode, so inside Xcode's own agents you use Xcode's test tools instead.Xcode's own MCP server (
xcrun mcpbridge, Xcode 26.3+):GetTestList,RunSomeTests,RunAllTests(Cursor's Xcode docs). The Xcode 27 release notes add debugger, scheme, destination and build-setting tools, plus a headless preview (sudo xcrun mcp-server enable). The Xcode 27.2 release notes do not name a GetCodeCoverage tool. Setup: Best MCP servers for Xcode; inside Xcode: Agents inside Xcode 27.XCAutokit:
test_simoverxcodebuild. axmcp: itsxcmcpserver wrapstestwithGetTestList/RunSomeTestsfor targeted runs.simless:
simless test uiruns your existing XCUITests in hidden hosts instead of simulator clones (its README reports 106 UI tests in 7.5 to 9.4 min vs 19.2 min on its own benchmark).
Step 3: Read the result bundle, not the console
The .xcresult bundle holds failures, screenshots and activity logs. Since Xcode 16 the JSON interface is xcresulttool get test-results …; the older get object needs --legacy (Apple Developer Forums, DTS answer; xcresulttool(1)):
bash
xcrun xcresulttool get test-results summary --path TestResults/login.xcresult --compact
xcrun xcresulttool get test-results tests --path TestResults/login.xcresult
xcrun xcresulttool export attachments --path TestResults/login.xcresult --output-path ./failures --only-failuressummary gives pass/fail counts and the failing tests; test-details and activities show the steps of one test; the failure screenshots let a vision-capable agent see what was on screen. Peekie wraps this in one subcommand per data type (peekie tests <xcresult> --format json) and ships a Claude Code skill.
Step 4: Flaky and "element not found" tests
Retry instead of guessing:
-retry-tests-on-failure(max 3 iterations by default),-run-tests-until-failure(max 100) and-test-iterations N, plus-test-repetition-relaunch-enabled YESfor a fresh process per run (xcodebuild man page). A test that fails only sometimes under-run-tests-until-failureis flaky; one that always fails is a real bug.Wrong or missing identifiers: iOS UI Testability Contract runs a local scanner (
uvx --from ios-ui-testability-contract ios-ui-testability ids <repo>) and a skill that tells the agent to inspect the runtime accessibility tree, patch the smallest app-side fix and rerun the focused test.Mixed frameworks: in Xcode 27, a Swift Testing assertion called from an XCTest (or the other way round) raises a runtime warning when it fails; the "Swift Testing and XCTest Interoperability" test-plan setting controls this (Xcode 27 release notes). Useful when an agent mixes the two.
Step 5: Agent-driven checks without test code
For a quick check of a change, an agent can drive the app and assert directly. These tools don't replace a regression suite; save the important journeys as tests (step 1) or with a tool that records replayable checks.
Assert from the agent: Testa (
testa assert "#status" label=…), averi (element, rect, color and OCR asserts, plusensure_statefrom anaveri.yamlin your repo), Manos (wait_for,assert,find_text) and agent-device ("asserting state").Replayable checks for CI: Maestro MCP ships inside the open-source Maestro CLI (
maestro mcp): the agent inspects, taps and asserts, then saves the steps as YAML flows under.maestro/that rerun withmaestro test(simulators only; physical iOS devices are not supported yet). Tapp saves reviewed journeys as replayable tests; only its repository-connected gate returns pass, fail or inconclusive.Goal-based UI tests: Harness runs AI user tests from a goal and persona against the simulator; UI XCute runs a goal-driven agent inside an XCTest via XCUIAutomation (Bedrock or local Ollama; alpha).
Real iPhone: iCTRL is a long-running XCUITest runner with a JSON-RPC API.
Test-and-debug harness: Autonom (Claude Code, Codex and Grok plugin; iOS Simulator and Android).
Setup for the drivers themselves: iOS simulator MCP servers compared.
UI testing tools in the catalog
Only entries whose README covers writing, running, reading or asserting UI tests. ⚠ = last push more than 6 months ago.
| Tool | Step | What it does for UI tests | Install (from README) | License | ★ (22 Oct) | Last push |
|---|---|---|---|---|---|---|
| MobileBuildMCP (getsentry) | Run | test_sim, test_device with structured results | npx -y mobilebuildmcp@latest mcp | MIT | 6,498 | 22 Oct 2026 |
| agent-device (callstack) | Agent check | Inspect, control and verify apps; waits and assertions | npm install -g agent-device@latest | MIT | 5,110 | 22 Oct 2026 |
| iCTRL (OpenMinis) | Agent check | XCUITest runner on a real iPhone, JSON-RPC API | Signed .ipa from releases | Apache-2.0 | 548 | 19 Oct 2026 |
| Harness (awizemann) | Agent check | Goal + persona user tests on simulator, macOS or web | Release zip (macOS 14+) | MIT | 357 | 2 Sep 2026 |
| Peekie (dodobrands) | Read | .xcresult → tests, errors, coverage, attachments as JSON | mise use github:dodobrands/peekie | Apache-2.0 | 32 | 21 Oct 2026 |
| simless (abacusai) | Run | Runs existing XCUITests without simulator clones | swift build -c release from a clone | Apache-2.0 | 26 | 22 Oct 2026 |
| iOS Testing (ioloro) | Write | XCUITest + Swift Testing skill, iostesting CLI | npm install -g @ioloro/ios-testing | MIT | 24 | 5 Aug 2026 |
| Testa (valewnrt) | Agent check | Reads the screen as text, taps, assert | brew tap valewnrt/testa && brew install testa | MIT | 3 | 8 Oct 2026 |
| XCAutokit (Ezra-Black) | Run | test_sim over xcodebuild, UI inspect and verify | npm install -g xcautokit@latest | MIT | 1 | 7 Oct 2026 |
| iOS MCP Code Quality (a-25) ⚠ | Run | Runs Xcode tests and SwiftLint, structured reports | npx ios-mcp-code-quality-server test … | MIT | 11 | 26 Sep 2025 |
| Manos (ryanperkins) | Agent check | Exploratory UI testing, wait_for/assert | claude mcp add manos -- npx -y manos-mcp serve | MIT | 3 | 18 Jun 2026 |
| averi (mholecy) | Agent check | Asserts + ensure_state from repo-owned averi.yaml | claude mcp add averi -- npx -y averi | MIT | 4 | 22 Oct 2026 |
| axmcp (tmc) | Run | xcmcp: test, GetTestList, RunSomeTests | go install github.com/tmc/axmcp/cmd/xcmcp@latest | MIT | 8 | 23 Sep 2026 |
| iOS UI Testability Contract (Kofiloski) | Fix | Scanner + skill for "element not found" / flaky XCUITests | uvx --from ios-ui-testability-contract … | MIT | 1 | 15 Jul 2026 |
| Maestro MCP (mobile-dev-inc) | Agent check → CI | maestro mcp: inspect, tap, assert, save YAML flows | curl -fsSL "https://get.maestro.mobile.dev" | bash | Apache-2.0 | 16,176 | 19 Oct 2026 |
| Maestro Mobile Testing Skill (foreztgump) | Write | Maestro flows for native iOS and other stacks | npx skills add foreztgump/maestro-mobile-testing-skill | MIT | 1 | 9 Oct 2026 |
| UI XCute (Andrea-Scuderi) | Agent check | Goal-driven agent inside XCTest via XCUIAutomation | Swift package 1.0.0-alpha.1 | Apache-2.0 | 4 | 15 Jun 2026 |
| Tapp (aarwitz) | Agent check → CI | Verifies UI changes, saves replayable journeys | npx -y skills add aarwitz/tapp --skill tapp | MIT | 2 | 22 Oct 2026 |
| Autonom (aiatsuk) | Agent check | Test/debug harness plugin, iOS Simulator + Android | claude plugin install autonom@autonom | MIT | 1 | 22 Oct 2026 |
Simulator drivers that don't run or assert tests (mobile-mcp, iOS Simulator MCP, iosef, serve-sim and others) are compared in iOS simulator MCP servers.
FAQ
- Can Claude Code or Codex write XCUITests?
- Yes. Ask for XCTest UI tests in your UI test target, querying elements by accessibility identifier. Apple's UI testing uses XCTest with the XCUIAutomation framework; Swift Testing is recommended for unit tests. Skills such as iOS Testing (ioloro) add XCUITest guidance, and Xcode 26 can record a flow as a starting point.
- How does an AI agent run a single iOS UI test?
- With xcodebuild test and -only-testing:TestTarget/TestClass/TestMethod, plus -resultBundlePath to keep the results. Through MCP, MobileBuildMCP's test_sim accepts extra xcodebuild arguments, and Xcode's own MCP server offers GetTestList and RunSomeTests while Xcode is running.
- How can an agent read UI test failures?
- Point it at the .xcresult bundle. xcrun xcresulttool get test-results summary --path <bundle> returns JSON with counts and failures, test-details and activities show the steps, and export attachments --only-failures saves the failure screenshots. Peekie wraps these as JSON subcommands.
- Should I use XCUITest or an AI agent that taps through the simulator?
- Both, for different jobs. XCUITest gives deterministic regression tests that run in CI. Agent-driven tools such as Testa, agent-device or Maestro MCP are faster for checking a change once, without writing test code. Save important journeys as tests.
- How do I deal with flaky UI tests with an agent?
- Rerun the test with -run-tests-until-failure or -retry-tests-on-failure to see whether it is flaky, then fix the cause. Missing or misplaced accessibility identifiers are a common one; the iOS UI Testability Contract skill scans for them and reruns the focused test.