agentleFS
TheDecipheristTheDecipherist/claude-code-mastery-project-starter-kit/.claude/skills/test-writer/SKILL.md

test-writer

Skill337 starsChanged 5 months agoMITView on GitHub

Write tests that catch bugs, with explicit assertions, realistic data, and proper structure. Use when asked to write, add, improve, or expand tests, or to raise coverage. Writes test files and runs them to confirm they assert real behavior.

28 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use debug-fix, changelog-writer 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.
  • zebbernSkill

    debug-fix

    Find and fix a bug or issue — from any source (GitHub issue, error message, user report, or observed behavior)

    Also in 4 projects that use this

  • zbruhnkeSkill

    changelog-writer

    Maintain CHANGELOG.md with properly categorized entries. Use after implementing features, fixing bugs, or making any notable changes. Follows Keep a Changelog format.

    Also in 5 projects that use this

  • glinckerSkill

    readme-generator

    Generates comprehensive README.md files for software projects by analyzing codebase structure

    Also in 4 projects that use this

  • get-proofpilotSkill

    context-budget

    Audits Claude Code context window consumption across agents, skills, MCP servers, and rules. Identifies bloat, redundant components, and produces prioritized token-savings recommendations.

    Also in 3 projects that use this

  • nimbalystSkill

    prd-writer

    Create structured Product Requirements Documents (PRDs) with prioritized requirements. Use when writing product specs, feature requirements, or project briefs.

    Also in 3 projects that use this

  • GoogleSkill

    code-reviewer

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 27 edited versions we read keep these.

  • 3

    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. Distinctive:

    Every test has explicit assertions.

    line 17
  2. Distinctive:

    Test behavior, not implementation details.

    line 18
  3. Very specific:

    Use realistic test data, never test / asdf.

    line 20
  4. Distinctive:

    Run the tests. A new test should fail against code that doesn't satisfy it and pass once it does.

    line 78

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

You write tests that catch bugs, not tests that pass. A test that can't fail isn't a test.

Principles

  1. Every test has explicit assertions. "Page loads" is not a test.
  2. Test behavior, not implementation details.
  3. Cover the happy path, the error cases, and the edge cases.
  4. Use realistic test data, never test / asdf.
  5. Tests are independent. No shared mutable state between them.

Structure

describe('[Feature]', () => {
  describe('[Scenario]', () => {
    it('should [expected behavior] when [condition]', async () => {
      // Arrange — set up test data
      // Act — perform the action
      // Assert — verify SPECIFIC outcomes
    });
  });
});

Assertions

// GOOD — explicit, specific
expect(result.status).toBe(200);
expect(result.body.user.email).toBe('ada@example.com');
await expect(page.locator('h1')).toContainText('Welcome');

// BAD — passes even when broken
expect(result).toBeTruthy();   // too vague
await page.goto('/dashboard'); // no assertion at all

Data-layer tests (this codebase)

The data layer has rules that test data must respect, or the test passes while masking the exact bug that bites in production.

  • Seed real ObjectId values, not string ids. The single most common production bug here is a string-vs-ObjectId _id mismatch that silently returns nothing. A test seeded with string ids passes and hides it. Use actual ObjectId types in fixtures.
  • Exercise the data adapter (StrictDB or native), not a hand-rolled driver mock. Tests go through the same adapters/ boundary the handlers use. Mock at the network or data boundary, not by reimplementing the driver.
  • Test the round trip. Where data is serialized (JSON in, JSON out), assert that types survive it, since that round trip is where _id mismatches and code-66 upsert errors appear.

Unit tests (Vitest)

Each test verifies:

  1. Return value matches expected.
  2. Side effects occurred, or provably didn't.
  3. Error cases throw the proper error.
  4. Edge cases: null, empty, max values, and for ids, wrong-type ids.

E2E tests (Playwright)

Each test verifies:

  1. Correct URL after navigation.
  2. Key elements are present.
  3. Correct data is displayed.
  4. Error states show the proper message.

Before finishing

Run the tests. A new test should fail against code that doesn't satisfy it and pass once it does. If a test passes the moment you write it without the behavior existing, it isn't asserting anything, fix the assertion.

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.