Skip to content
SwiftSkills

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?

GoalApproachSteps
A regression test that runs in CI on every PRAgent writes XCUITest, runs it, reads .xcresult1–3
"Did my change break the login flow?" right nowRun the existing UI test for that flow with -only-testing2–3
Fix a flaky or "element not found" UI testRetry flags + accessibility-identifier fixes4
Quick check of a new screen without writing a testAgent-driven check: drive the simulator and assert5
Goal-based exploratory testing ("buy the first item")AI user-test tools5

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-testing identifier (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 parent VStack instead of the TextField) 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 XCUIVoiceOverService for 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 iostesting CLI 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.xcresult
  • Test identifiers have the form TestTarget[/TestClass[/TestMethod]]; -only-testing wins over -skip-testing, and you can pass a response file with @file.

  • -testPlan <name> picks a test plan; -only-test-configuration limits it to one configuration.

  • build-for-testing once, then test-without-building for repeated runs.

Through MCP instead of a shell command:

  • MobileBuildMCP: test_sim ("Test on iOS sim.") and test_device, with structured test-result output and extraArgs for flags such as -only-testing (tool manifests). Note: both are marked hideWhenXcodeAgentMode, 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_sim over xcodebuild. axmcp: its xcmcp server wraps test with GetTestList / RunSomeTests for targeted runs.

  • simless: simless test ui runs 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-failures

summary 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 YES for a fresh process per run (xcodebuild man page). A test that fails only sometimes under -run-tests-until-failure is 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, plus ensure_state from an averi.yaml in 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 with maestro 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.

ToolStepWhat it does for UI testsInstall (from README)License★ (22 Oct)Last push
MobileBuildMCP (getsentry)Runtest_sim, test_device with structured resultsnpx -y mobilebuildmcp@latest mcpMIT6,49822 Oct 2026
agent-device (callstack)Agent checkInspect, control and verify apps; waits and assertionsnpm install -g agent-device@latestMIT5,11022 Oct 2026
iCTRL (OpenMinis)Agent checkXCUITest runner on a real iPhone, JSON-RPC APISigned .ipa from releasesApache-2.054819 Oct 2026
Harness (awizemann)Agent checkGoal + persona user tests on simulator, macOS or webRelease zip (macOS 14+)MIT3572 Sep 2026
Peekie (dodobrands)Read.xcresult → tests, errors, coverage, attachments as JSONmise use github:dodobrands/peekieApache-2.03221 Oct 2026
simless (abacusai)RunRuns existing XCUITests without simulator clonesswift build -c release from a cloneApache-2.02622 Oct 2026
iOS Testing (ioloro)WriteXCUITest + Swift Testing skill, iostesting CLInpm install -g @ioloro/ios-testingMIT245 Aug 2026
Testa (valewnrt)Agent checkReads the screen as text, taps, assertbrew tap valewnrt/testa && brew install testaMIT38 Oct 2026
XCAutokit (Ezra-Black)Runtest_sim over xcodebuild, UI inspect and verifynpm install -g xcautokit@latestMIT17 Oct 2026
iOS MCP Code Quality (a-25) ⚠RunRuns Xcode tests and SwiftLint, structured reportsnpx ios-mcp-code-quality-server test …MIT1126 Sep 2025
Manos (ryanperkins)Agent checkExploratory UI testing, wait_for/assertclaude mcp add manos -- npx -y manos-mcp serveMIT318 Jun 2026
averi (mholecy)Agent checkAsserts + ensure_state from repo-owned averi.yamlclaude mcp add averi -- npx -y averiMIT422 Oct 2026
axmcp (tmc)Runxcmcp: test, GetTestList, RunSomeTestsgo install github.com/tmc/axmcp/cmd/xcmcp@latestMIT823 Sep 2026
iOS UI Testability Contract (Kofiloski)FixScanner + skill for "element not found" / flaky XCUITestsuvx --from ios-ui-testability-contract …MIT115 Jul 2026
Maestro MCP (mobile-dev-inc)Agent check → CImaestro mcp: inspect, tap, assert, save YAML flowscurl -fsSL "https://get.maestro.mobile.dev" | bashApache-2.016,17619 Oct 2026
Maestro Mobile Testing Skill (foreztgump)WriteMaestro flows for native iOS and other stacksnpx skills add foreztgump/maestro-mobile-testing-skillMIT19 Oct 2026
UI XCute (Andrea-Scuderi)Agent checkGoal-driven agent inside XCTest via XCUIAutomationSwift package 1.0.0-alpha.1Apache-2.0415 Jun 2026
Tapp (aarwitz)Agent check → CIVerifies UI changes, saves replayable journeysnpx -y skills add aarwitz/tapp --skill tappMIT222 Oct 2026
Autonom (aiatsuk)Agent checkTest/debug harness plugin, iOS Simulator + Androidclaude plugin install autonom@autonomMIT122 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.