agentleFS
cenconq25cenconq25/claude-code-app-studio/.claude/skills/test-helpers/SKILL.md

test-helpers

Skill41 starsChanged 7 months agoMITView on GitHub

Generates a framework-specific test helper library — factories, mocks, custom matchers, and shared assertion utilities — under tests/helpers/. Reduces boilerplate in new test files. Run after /test-setup once the project has a few real tests.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 2

    Distinctive

    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:

    Use AskUserQuestion to confirm:

    line 65
  2. Very specific:

    Create files under tests/helpers/ grouped by purpose.

    line 75
  3. Very specific:

    Create tests/helpers/README.md with one short section per helper:

    line 136
  4. Distinctive:

    Keep entries terse — engineers will skim, not read.

    line 143
  5. Very specific:

    Run /test-evidence-review after the next sprint to verify the helpers are actually being used.

    line 185

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “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

Test Helpers

Reads existing tests, finds repeated setup, and extracts that into a helper library so future tests stay short and intention-revealing.


Phase 1: Read Project Context

Read in parallel:

  • .claude/docs/technical-preferences.md — Framework, Testing Framework, Naming Conventions.
  • .claude/docs/coding-standards.md — test rules.
  • tests/helpers/ (if present) — what already exists.

Confirm the framework. If unset, redirect to /setup-framework.


Phase 2: Scan Existing Tests

Glob the test tree:

  • RN/TS: tests/**/*.test.{ts,tsx,js,jsx}
  • Flutter: tests/**/*_test.dart and test/**/*_test.dart
  • iOS: tests/**/*Tests.swift
  • Android: tests/**/*Test.kt

For each file, find:

  • Repeated factory functions (e.g., builders that return a User, Product, CartItem, etc.).
  • Repeated mocks (network client, storage, analytics, deep-link router, push handler).
  • Repeated assertion patterns (e.g., "the screen shows error X" or "the store dispatched action Y").
  • Repeated setup/teardown blocks (auth state, seed data, navigation stack).

Group results by recurrence count. Anything that appears 3+ times is a candidate.


Phase 3: Propose the Helper API

Produce a proposal table:

HelperTypeUsed inReason
makeUser({...overrides})Factory8 testsduplicated user objects
mockApiClient(responses)Mock5 testsrepeated fetch stubs
expectScreenShowsError(matcher)Matcher4 testsrepeated assertion

Use AskUserQuestion to confirm:

  • [A] Generate every helper in the table
  • [B] Generate only the top N
  • [C] Let me pick — show one at a time

Phase 4: Write the Helpers

Create files under tests/helpers/ grouped by purpose. Always ask before each write. Naming follows the framework convention.

Factories — tests/helpers/factories/*

Pattern: pure functions that take an overrides object and return a fully-formed domain object with sensible defaults.

// React Native example
export const makeUser = (overrides: Partial<User> = {}): User => ({
  id: 'user-1',
  email: 'a@b.com',
  isVerified: true,
  ...overrides,
});

Mocks — tests/helpers/mocks/*

Pattern: factory functions that return an interface-shaped mock object. For each platform module the project commonly stubs (network, storage, analytics, biometrics, push, location), provide a mock factory.

Custom matchers — tests/helpers/matchers/*

Wrap repeated assertions in named matchers with clear failure messages. Examples:

  • toHaveDispatched(action) for a Redux store.
  • toRenderError(message) for a screen-level error UI.
  • toMatchSnapshotIgnoring([fields]) for resilient snapshot tests.

Test fixtures — tests/helpers/fixtures/*

For canned responses (paginated lists, deep-link payloads, push payloads), provide JSON fixtures plus a small loader utility.

Render helpers — tests/helpers/render.{ts,dart,swift,kt}

Wrap the framework's render call to also wire navigation, theme, store, and i18n providers in one call:

  • RN: renderWithProviders(ui, { store, navState })
  • Flutter: pumpWithProviders(tester, widget, { router, theme })
  • SwiftUI: RenderHost(view).withStubbedDeps()
  • Compose: composeTestRule.setContentWithProviders { ui }

Phase 5: Refactor One Existing Test as a Demo

Pick the highest-duplication file from Phase 2. Refactor it to use the new helpers. Show the diff and ask the user to approve before saving.

This proves the helpers work and provides a reference for future authors.


Phase 6: Document the Helpers

Create tests/helpers/README.md with one short section per helper:

  • Signature
  • One-line purpose
  • One-line usage example
  • The original-pattern problem it replaces

Keep entries terse — engineers will skim, not read.


Phase 7: Update Coding Standards

Append a Test Helpers block to .claude/docs/coding-standards.md:

  • Where helpers live.
  • The rule: "Before adding a third copy of any test setup, extract it into tests/helpers/."
  • The rule: "New tests must use existing helpers when applicable."

Confirm before writing.


Quality Gates / PASS-FAIL

  • PASS — every generated helper compiles; the demo refactored test still passes; README exists; standards updated.
  • FAIL — any helper has a type error or runtime error in the smoke run. Roll back the failing helper and surface the diagnostic.

Examples

Example 1 — RN app with 14 tests: Detects that 9 tests build a Product object inline. Generates makeProduct, refactors tests/unit/cart/cartReducer.test.ts to use it, adds a README entry, and updates standards.

Example 2 — Flutter app: Detects a pumpWithRouter pattern repeated across widget tests. Extracts tests/helpers/pump.dart and refactors one widget test as the canonical example.


Next Steps

  • Run /test-evidence-review after the next sprint to verify the helpers are actually being used.
  • Re-run /test-helpers --scan periodically (start of each sprint) to catch new duplication early.

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.