agentleFS
kriscardkriscard/Skills/skills/dev/test/SKILL.md

test

Skill14 starsChanged 4 months agoMITView on GitHub

Applies test-pyramid, red-green-refactor, and behavioral testing practices for common JS/Python/Ruby stacks and other projects after detecting the runner. Use when the user says "write tests", "add tests", "TDD", "test coverage", "this test is failing", or mentions Jest/Vitest/pytest/RSpec/Playwright/ Cypress. Also use when a feature is implemented without tests.

98 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use develop, perf and 8 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • bamechoSkill

    develop

    开发实施阶段详细规则;进入开发实施时读取;包含执行流程、代码规范、一致性审计、方案包迁移

    Also in 6 projects that use this

  • MicrosoftSkill

    perf

    Speed and memory performance rules for Rust crates, the Node addon, webui-framework, and webui-router.

    Also in 6 projects that use this

  • nicolasestremSkill

    document

    Create focused documentation for specific components or features

    Also in 8 projects that use this

  • vltingSkill

    scope

    Interactive planning + orchestration. Approval-gated workflow covering saga→epic→task hierarchy via progressive scoping.

    Also in 5 projects that use this

  • kt057Skill

    check

    lint, typecheck, test を一括実行して結果をサマリーする

    Also in 8 projects that use this

  • Google CloudSkill

    fix

    Plan a remediation strategy after a test failure.

    Also in 10 projects that use this

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 80 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Don't assume Jest. Vitest is increasingly common in Vite/Next.js projects.

    line 36

“Common” is measured: kept by at least 6 in 10 of the 80 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

Pick the Right Layer First

Writing tests at the wrong layer is the most common testing mistake. A unit test that mocks everything doesn't catch integration bugs; an E2E test for a pure function is slow and fragile.

LayerWhat it testsSpeedWhen to use
UnitPure functions, isolated logic~msBusiness logic, utilities, transformations
IntegrationService boundaries, DB queries, API contracts~secondsRepository layer, HTTP handlers, queue consumers
E2EUser flows in a real browser~minutesCritical paths only (checkout, auth, onboarding)

The pyramid holds: many units, fewer integrations, minimal E2E. Done only when the selected layer is named and justified.

Detect the Framework

Check before choosing:

cat package.json | grep -E '"jest"|"vitest"|"mocha"|"jasmine"'
cat pyproject.toml | grep -E 'pytest|unittest'
cat Gemfile | grep rspec

Don't assume Jest. Vitest is increasingly common in Vite/Next.js projects. Mixing test runners in a project is rarely intentional. For unfamiliar stacks, inspect project config and docs before writing tests.

Universal Quality Checks

  • Tests cover error paths and edge cases, not just the happy path
  • Tests verify behavior, not implementation — if you rename a private method, tests shouldn't break
  • Mocks are used sparingly — over-mocking makes tests pass while real code breaks
  • Test names read like specs: should return 404 when user is not found beats test user endpoint
  • AAA pattern: Arrange → Act → Assert, with a blank line between sections

Red-Green-Refactor Flow (when requested)

  1. Red — write a failing behavioral test that describes the desired behavior; done only when the relevant test command fails for the expected reason
  2. Green — write the minimal code to make it pass; done only when the same command passes
  3. Refactor — clean up while keeping tests green; done only when the command still passes after cleanup

Integration Test Methodology

Integration tests validate service boundaries — not business logic (that's unit tests) and not full user flows (that's E2E).

What to test at this layer:

  • API endpoints: request/response structure, auth, error codes
  • Database queries: ORM behavior, transactions, constraint violations
  • Service-to-service contracts (Pact consumer-driven contract tests)
  • Message queue consumers and event handlers

Data isolation — non-negotiable:

  • Wrap each test in a transaction and roll back, or reset the test DB between runs
  • Tests that share state cause order-dependent failures — the hardest class of flakiness to debug
  • Mock third-party APIs, not your own services

Load references for runner-specific APIs, mocks, environments, MSW, Browser Mode, snapshots, type testing, coverage, and configuration.

E2E Test Methodology

E2E tests are expensive. Use them only for critical paths: checkout, auth, onboarding, file upload. Prefer accessible selectors, smart waits, unique test data, and cleanup via API or DB reset. Cover edge cases in unit/integration tests, not E2E.

Common Pitfalls

  • Testing the mock, not the code — if the test only asserts a mock was called, it may not test behavior
  • Fragile E2E selectors — use roles or stable test IDs instead of layout selectors
  • No cleanup in integration tests — shared DB state causes order-dependent failures
  • Snapshot tests as a crutch — use snapshots only for stable, serializable outputs

Completion Gate

Complete test work only after:

  • the selected layer is named
  • the relevant test command has been run
  • failures are either fixed or reported with evidence
  • new tests would fail against the old behavior when that can be checked
  • red/green command output is reported for TDD work

References

PriorityLoad whenReference
1 — HighWriting Vitest test blocks, test.each, or test modifiersreferences/core-test-api.md
1 — HighWriting Vitest assertions, spies, soft assertions, or custom matchersreferences/core-expect.md
1 — HighMocking modules, timers, globals, or partial implementations in Vitestreferences/features-mocking.md
2 — HighConfiguring Vitest projects, pools, environments, globals, or defineConfigreferences/core-config.md
2 — HighUsing Vitest hooks such as beforeEach, afterEach, beforeAll, afterAll, aroundEach, or onTestFinishedreferences/core-hooks.md
3 — MediumCoverage providers, thresholds, reporters, or ignore commentsreferences/features-coverage.md
3 — MediumReal browser testing via Vitest Browser Mode / Playwright providerreferences/browser-mode.md
3 — MediumSnapshots, inline snapshots, custom serializers, or updating snapshotsreferences/features-snapshots.md
3 — MediumCLI filtering, --changed, tags, test.only, or test.skipreferences/features-filtering.md
4 — LowNested suites, describe.concurrent, or describe.eachreferences/core-describe.md
4 — LowVitest CLI watch mode, sharding, or package.json scriptsreferences/core-cli.md
4 — Lowtest.concurrent, file parallelism, sequence, or shufflereferences/features-concurrency.md
4 — Lowtest.extend, fixture scopes, or auto fixturesreferences/features-context.md
4 — Lowjsdom vs happy-dom vs node, custom environments, or CSS handlingreferences/advanced-environments.md
4 — LowexpectTypeOf, assertType, .test-d.ts, or vitest typecheckreferences/advanced-type-testing.md
4 — LowFake timers, vi.waitFor, or vi.mocked deep divereferences/advanced-vi.md
4 — LowMonorepo or multi-project Vitest setupsreferences/advanced-projects.md
4 — LowMSW v2 http.*/HttpResponse handlers, Node setup, or v1→v2 migrationreferences/msw-v2.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.