ios-unit-tests
Skill1 starsChanged 14 days agoMITView on GitHub
Write or extend unit tests in this iOS codebase using its existing seams and test doubles — StubHTTPSession, StubAPIClient, in-memory cache and outbox, spy auth. Use when asked to add tests, improve coverage, test a repository or view model, test networking, retry, token refresh or offline behaviour, or when a bug needs a regression test before it is fixed.
In this repository37 other files it gives its agents.
- AGENTS.mdAGENTS.md
- ios-accessibility-auditSkill
- ios-api-contract-migrationSkill
- ios-api-endpointSkill
- ios-app-intents-siriSkill
- ios-bug-triageSkill
- ios-build-configurationSkill
- ios-cloudkit-syncSkill
- ios-combine-patternsSkill
- ios-commit-and-prSkill
- ios-commitSkill
- ios-concurrency-auditSkill
- ios-coreml-apple-intelligenceSkill
- ios-deep-linkingSkill
- ios-dependency-assessmentSkill
- ios-design-fixSkill
- ios-feature-moduleSkill
- ios-knowledge-baseSkill
- ios-latest-os-adoptionSkill
- ios-localizationSkill
- ios-offline-writeSkill
- ios-performance-tuningSkill
- ios-port-from-androidSkill
- ios-port-to-androidSkill
- ios-precommitSkill
- ios-privacy-complianceSkill
- ios-push-and-background-tasksSkill
- ios-refactorSkill
- ios-release-prepSkill
- ios-sdk-upgradeSkill
- ios-secure-reviewSkill
- ios-storekit-subscriptionsSkill
- ios-swift6-concurrency-migrationSkill
- ios-swiftdataSkill
- ios-swift-testing-migrationSkill
- ios-swiftui-screenSkill
- ios-widgetkit-live-activitiesSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 5 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 10
Every awkward path in this app is testable without a simulator network, a live backend or URLProtocol tricks, because of four seams:
- Distinctive: line 27
Test behaviour, not implementation.
- Very specific: line 29
Prefer the real object under test with doubles beneath it.
- Distinctive: line 36
No sleeps to synchronise. Await the work.
- Distinctive: line 39
Never name a local variable the same as a method used in the same scope — Swift will not forgive it.
- Distinctive: line 41
Test data is invented. No client names, no real addresses, no personal data, no credentials — not even plausible-looking ones.
- Distinctive: line 51
every offline write path and its replay.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.
Files
Write tests
The seams
Every awkward path in this app is testable without a simulator network, a live
backend or URLProtocol tricks, because of four seams:
| Seam | Double | Use it to test |
HTTPSession | StubHTTPSession | Real LiveAPIClient: status mapping, retry, 401 refresh-and-retry, decoding failures |
APIClient | StubAPIClient | Real repository: read policies, cache, offline queueing, replay |
CacheStore / Outbox | InMemoryCacheStore / InMemoryOutbox | Repository behaviour with no disk |
<X>Repository | StubWidgetRepository | Real view model: states, banners, rollbacks |
AuthenticationAPI / TokenStorage | SpyAuthenticationAPI / InMemoryTokenStorage | Real AuthSessionStore: single-flight refresh, sign-out |
Extend the existing doubles rather than adding new ones. They live in
AppTemplateTests/Support; the in-memory app-target implementations live beside
their protocols.
Rules
- Test behaviour, not implementation. "A POST is never retried automatically", not "the retry policy's delay function returns nil".
- Prefer the real object under test with doubles beneath it. Testing
LiveAPIClientover a stub session is far more valuable than testing a mock of it. - View-model test classes are
@MainActor final class ... : XCTestCase. - Name tests as sentences:
testFailedDeleteRestoresTheRow. - Assertion messages explain the rule, not the values:
XCTAssertEqual(count, 1, "Ten concurrent callers must cause exactly one refresh"). - No sleeps to synchronise. Await the work. Where a delay is genuinely needed to create overlap (the single-flight test), inject it into the double.
- Actor state is read with
await:let count = await api.refreshCount. - Never name a local variable the same as a method used in the same scope — Swift will not forgive it.
- Test data is invented. No client names, no real addresses, no personal data, no credentials — not even plausible-looking ones.
What to cover
For a repository:
- each
ReadPolicythe feature actually uses; - cache hit avoids the network (assert on the request count, not just the result);
- offline falls back to cache and reports
.cacheWhileOffline; .remoteOnlydoes not fall back;- every offline write path and its replay;
- validation rejected before any request leaves the device.
For a view model:
- success populates state;
- failure with no content →
.failed; - failure with existing content → content kept plus banner;
- cancellation produces nothing visible;
- each mutation, including its rollback on failure.
For networking:
- one test per
APIErrorcase the app depends on; - retry happens for idempotent methods and never for POST;
- 401 refreshes once, retries once, and does not loop.
Running them
./Scripts/build.sh test developmentor directly, naming the environment's scheme and configuration:
xcodebuild test -scheme AppTemplate-Development -configuration Debug-Development \
-destination 'platform=iOS Simulator,name=iPhone 15'Tests must run on a Debug-* configuration: @testable import needs
ENABLE_TESTABILITY, which only the Debug flavour sets.
Verification
- Each new test fails if the behaviour it describes is broken — check by reasoning through the change, or by temporarily inverting the logic.
- No test depends on wall-clock timing to pass.
- No test data resembles real client or personal data.
- Failure paths are covered, not just the happy path.
- Tests were actually run, or say plainly that they were not and why.
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
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.

