Skills

Unit test writer that follows your project's existing test conventions

A Claude Code skill that writes focused unit tests for named functions or recent changes, matching the framework, file layout and helpers your repo already uses, then runs only the new tests until they pass.

Skill in Engineering by AISkillHub Library

What it does

Asking an agent to "add tests" often produces tests in the wrong framework, in the wrong folder, mocking the very thing under test, or asserting whatever the code currently returns. This skill fixes that by making Claude Code study the project's existing tests first and then follow a strict sequence.

**How it works** 1. Detects the test runner from project files (Jest, Vitest, pytest, Go's `testing` package, PHPUnit or Pest, RSpec, and others it can identify from config). 2. Reads two or three existing test files near the target code to copy naming, file placement, fixtures, factories and assertion style. 3. Lists the behaviors to cover before writing anything: the main path, boundaries, invalid input, and error handling. 4. Writes the tests, runs only the new test file, and iterates on failures.

**Rules it follows** - Tests describe intended behavior. If a test fails because the source looks wrong, it stops and reports the suspected bug instead of changing the assertion to match. - It never edits source code to make tests pass without asking. - It mocks only external boundaries (network, clock, filesystem, third-party SDKs), never the unit under test. - No snapshot tests unless the project already uses them for that kind of code.

**What it will not do** It does not write end-to-end or browser tests, chase a coverage percentage, or restructure your test suite.

**Example** `/write-unit-tests src/lib/slugify.ts` produces `src/lib/slugify.test.ts` with cases for accents, repeated separators, empty string and max length, runs `npx vitest run src/lib/slugify.test.ts`, and reports 7 passing tests plus one suspected bug: trailing hyphens are not trimmed.

How to use it

1. Create `.claude/skills/write-unit-tests/` in your repository and save the file below as `SKILL.md` inside it. 2. In Claude Code, ask naturally ("write tests for the date helpers") or invoke it with a target: `/write-unit-tests path/to/file.ext` or `/write-unit-tests functionName`. 3. With no argument, it targets functions changed since the last commit (`git diff HEAD`). 4. Make sure your test dependencies are installed first so the skill can run the tests it writes.

Files

Save each file at the path shown, relative to your project root.

  • .claude/skills/write-unit-tests/SKILL.md2.7 KB

More skills

See all