agentleFS
raulrieraraulriera/skills/xcuitest-best-practices/SKILL.md

xcuitest-best-practices

Skill2 starsChanged 4 months agoMITView on GitHub

Use when writing, reviewing, or debugging XCUITest UI tests for iOS apps. Makes tests idempotent, free of manual setup, and portable between local runs and Xcode Cloud. Covers app-state reset before service construction, page objects, readiness waits, system alerts and permissions, custom gestures, relaunch and persistence checks, secrets, and flaky-test diagnosis. Symptoms: a test passes alone but fails in a full run or on CI, taps miss, waits time out, the app starts in the wrong state.

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 11 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈11

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every test is self-contained.

    line 23
  2. Distinctive:

    Do not replace the behavior under test with a fake.

    line 29
  3. Distinctive:

    Use accessibility identifiers only where a label is not unique or not stable, and only if the project allows them.

    line 32
  4. Very specific:

    Wait for readiness (exists, isHittable, isEnabled, or a proven data-ready state) before every action.

    line 34
  5. Distinctive:

    Do not retry committed actions (create, save, send, pay) and do not dismiss alerts automatically.

    line 37
  6. Distinctive:

    Start a test that only needs a signed-in account in a prepared state, set by a Debug simulator launch flag, never a deep link.

    line 41
  7. Very specific:

    Use only standard XCUITest APIs in test code: no Process, xcrun simctl, or host file access.

    line 43
  8. Distinctive:

    Never type, log, or attach real credentials or personal data.

    line 44
  9. Distinctive:

    If the project says only a person runs UI tests, build them but do not run them, and say clearly that a build is not a run.

    line 45
  10. Distinctive:

    If the flow needs network data, credentials, or system permissions.

    line 53
  11. Distinctive:

    If it fails always, only in a full run, only on CI, or only on one device type.

    line 54
  12. Distinctive:

    No test depends on another test's result or on state from an earlier run.

    line 93
  13. Distinctive:

    Every launch turns off animations with a Debug simulator flag.

    line 98
  14. Very specific:

    Test code uses no Process, simctl, or host paths.

    line 100

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

XCUITest Best Practices

Overview

A UI test drives the real app as a person would. It must prepare its own state, prove each screen is ready before it acts, act once, and fail at the first unexpected result. Investigate timing, data readiness, and setup ownership before you add a retry.

Project rules (for example in AGENTS.md, CLAUDE.md, or a testing guide) take priority over this skill.

Agent behavior contract

  1. Every test is self-contained. It resets the state it needs at launch, does not depend on test order, and leaves nothing that changes the next run.
  2. Tests need no manual step: no reset command, no simulator setting, no specific test order. Host-only preparation goes in the scheme's Test pre-action, never in the test process.
  3. Reset app state inside the app, before services are constructed, behind an explicit launch flag that only Debug simulator builds read. Remove the flag before a relaunch that checks persistence.
  4. Do not replace the behavior under test with a fake. End-to-end tests use production implementations and normal storage unless the project defines another boundary.
  5. Query by visible text and accessibility labels first. They test what people see and hear. Use accessibility identifiers only where a label is not unique or not stable, and only if the project allows them.
  6. Wait for readiness (exists, isHittable, isEnabled, or a proven data-ready state) before every action. Never use sleep as a wait.
  7. A timed-out wait throws and ends the test. Do not continue with dependent steps.
  8. Do not retry committed actions (create, save, send, pay) and do not dismiss alerts automatically. An unexpected alert fails the test at once.
  9. Give the app one driver and each feature one page object. The driver knows no feature's screens, and a page holds only its own feature's steps. Tests read as user steps and outcomes.
  10. Start a test that only needs a signed-in account in a prepared state, set by a Debug simulator launch flag, never a deep link. Keep one test that drives the real sign-in flow.
  11. Use only standard XCUITest APIs in test code: no Process, xcrun simctl, or host file access.
  12. Never type, log, or attach real credentials or personal data. UI test logs record typed text.
  13. If the project says only a person runs UI tests, build them but do not run them, and say clearly that a build is not a run.

First 60 seconds (triage)

  • Find the goal: a new test, a review, a flaky failure, or CI preparation.
  • Find the facts:
    • Which screens and services the flow touches, and which persistent state it reads or writes.
    • If the flow needs network data, credentials, or system permissions.
    • If it fails always, only in a full run, only on CI, or only on one device type.
  • Branch:
    • wrong start state or a test that depends on test order → references/state-and-idempotency.md
    • taps that miss, waits that time out, data not loaded → references/waiting-and-interaction.md
    • repeated queries or long tests → references/page-objects.md
    • permission alerts, share sheets, background, deep links → references/system-ui.md
    • secrets, pre-actions, Xcode Cloud → references/ci-and-xcode-cloud.md
    • a failure you cannot explain → references/diagnosing-failures.md

Routing map

  • Reset hooks, turning off animations, prepared start states, launch and relaunch, remote state, fixtures → references/state-and-idempotency.md
  • Readiness predicates, scrolling, moving content, gestures → references/waiting-and-interaction.md
  • The shared app driver, one page per feature, test layout and naming → references/page-objects.md
  • SpringBoard alerts, permission resets, share sheets, backgrounding, URLs → references/system-ui.md
  • Local and Xcode Cloud configuration, secrets, test plans → references/ci-and-xcode-cloud.md
  • Simulator clones, result bundles, regression tests → references/diagnosing-failures.md

Common pitfalls → next best move

SymptomCauseFix
Wrong start state on launchReset runs after services start workReset before service construction
Passes alone, fails in a full runLeftover state, or a parallel cloneReset per launch; read logs from the simulator the run used
Tap misses a dialog buttonThe dialog is still animatingWait for isHittable
"Expected X to exist" after an actionData not loaded yetWait for a proven ready state, then act once
app.open(url) starts in the wrong stateopen does not apply launchArgumentslaunch() first, then open(url)
System alert not foundIt belongs to SpringBoardQuery XCUIApplication(bundleIdentifier: "com.apple.springboard")
Share sheet action not foundActions are cellsQuery app.cells["Copy"]
Slide control does nothingtap() is a touch, not activationDrag with press(forDuration:thenDragTo:)
Tap lands on the wrong rowContent moved after the scrollSwipe slowly, then wait for a stable frame
Two buttons share one labelA sheet covers the screen behind itScope by container, or take the hittable match
Passes locally, fails on CIHost command or a missing secretStandard APIs only; supply secrets through CI configuration
One broken sign-in screen fails every testEach test drives sign-inLaunch in a prepared state; keep one sign-in test
A feature's steps live on the driver or another pageNo page for that featureAdd the feature's page and move the steps there

Verification checklist

  • Each test launches with the reset flag and passes when run alone, twice in a row, and in the full plan.
  • No test depends on another test's result or on state from an earlier run.
  • Each action waits for readiness; each wait throws on timeout.
  • No sleep, no generic alert dismissal, no retry of a committed action.
  • Queries use user-facing text where it is unique and stable.
  • Relaunches that check persistence omit the reset flag.
  • Every launch turns off animations with a Debug simulator flag.
  • Remote state that a test creates is unique to the run or removed by the test.
  • Test code uses no Process, simctl, or host paths; secrets come from configuration.
  • One page per feature owns its queries; the driver holds no feature steps; tests read as user steps.
  • Tests that only need a signed-in account start from the prepared-state flag; one test drives the real sign-in.

References

  • references/state-and-idempotency.md
  • references/waiting-and-interaction.md
  • references/page-objects.md
  • references/system-ui.md
  • references/ci-and-xcode-cloud.md
  • references/diagnosing-failures.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.