Unit Test Writer

Writes focused unit tests for a function or module — covering the happy path, edge cases, and error handling — in the project's existing test framework.

Reviewed Jul 7, 2026Testing & QAby AI World InformationMIT

What this skill does

Key features

  • Detects and matches the project's existing test framework and style
  • Covers happy path, edge cases, and error handling deliberately
  • Names tests by behaviour, not implementation
  • Doesn't test private internals or over-mock

Use cases

  • Backfilling tests for untested code
  • Adding edge-case coverage to a fragile function
  • Scaffolding tests in TDD before implementing

SKILL.md

The skill definition — its metadata and the exact instructions an agent follows. Copy it into a SKILL.md file in your agent's skills folder.

nametest-writer
descriptionWrite focused unit tests for a target function using the project's test framework.
allowed-toolsRead, Grep, Bash(ls:*)
coveragehappy path + edges + errors

Musts

  • Detect the existing test framework (look for jest/vitest/pytest config and existing test files) and match its style.
  • Cover, deliberately: the happy path, boundary/edge cases, and error/invalid-input handling.
  • Name each test by the behaviour it verifies (returns 0 for an empty list), not the implementation.
  • Test observable behaviour through the public API — don’t reach into private internals.

Guidelines

  • Mock external I/O (network, filesystem, clock) but avoid over-mocking pure logic.
  • One assertion focus per test; use clear arrange/act/assert structure.
  • If a function is hard to test, say why (it likely needs refactoring) rather than writing a brittle test.

Example (Jest)

describe('slugify', () => {
  it('lowercases and hyphenates spaces', () => {
    expect(slugify('Hello World')).toBe('hello-world');
  });
  it('returns an empty string for empty input', () => {
    expect(slugify('')).toBe('');
  });
});

FAQ

Does it run the tests?
It writes them; running is a separate step you control. It will note how to run them (e.g. `npm test`) but won't execute anything on its own here.
Will it reach 100% coverage?
Coverage is a means, not a goal. It targets meaningful behaviours and edge cases; chasing 100% often just tests trivia. Review what it wrote.

Before running any skill, read its instructions and the tools it's allowed to use, and test it on a safe target first. See LLM security best practices.