agentleFS
SajidisrarSajidisrar/ios-claude-skills/skills/ios-unit-tests/SKILL.md

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.

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
  1. Very specific:

    Every awkward path in this app is testable without a simulator network, a live backend or URLProtocol tricks, because of four seams:

    line 10
  2. Distinctive:

    Test behaviour, not implementation.

    line 27
  3. Very specific:

    Prefer the real object under test with doubles beneath it.

    line 29
  4. Distinctive:

    No sleeps to synchronise. Await the work.

    line 36
  5. Distinctive:

    Never name a local variable the same as a method used in the same scope — Swift will not forgive it.

    line 39
  6. Distinctive:

    Test data is invented. No client names, no real addresses, no personal data, no credentials — not even plausible-looking ones.

    line 41
  7. Distinctive:

    every offline write path and its replay.

    line 51

≈ “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.

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

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:

SeamDoubleUse it to test
HTTPSessionStubHTTPSessionReal LiveAPIClient: status mapping, retry, 401 refresh-and-retry, decoding failures
APIClientStubAPIClientReal repository: read policies, cache, offline queueing, replay
CacheStore / OutboxInMemoryCacheStore / InMemoryOutboxRepository behaviour with no disk
<X>RepositoryStubWidgetRepositoryReal view model: states, banners, rollbacks
AuthenticationAPI / TokenStorageSpyAuthenticationAPI / InMemoryTokenStorageReal 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 LiveAPIClient over 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 ReadPolicy the 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;
  • .remoteOnly does 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 APIError case 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 development

or 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.

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.