Skip to content

commandTesting

Write Tests

Writes tests for a named file or function in your existing test style, runs them and reports what they cover and what they miss.

npx workspacetemplates add write-tests --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/write-tests.md14 lines · 1.1 KBFile
---
description: Writes tests for a named file or function in your existing test style, runs them and reports what they cover and what they miss.
argument-hint: "<file or function to test>"
---

Write tests for: $ARGUMENTS

1. Read the target and what it depends on. Then find the closest existing test file and copy its runner, imports, naming, fixtures and mocking style. Find the test command in package.json, pyproject.toml, Makefile or the CI file.
2. List the behaviors first: the normal path, boundaries (empty, zero, one, maximum), invalid input, error paths, and any ordering or time dependence.
3. Write one test per behavior with a name that states the expectation. Assert on outputs and visible effects, not on internals. Mock only I/O boundaries such as network, clock and filesystem.
4. Run only the new tests. If one fails, decide whether the test or the code is wrong. Never weaken an assertion to get green.
5. Put the file next to the others, following project layout.

Report: the tests added, the command to run them, behaviors deliberately left out, and any real bug found. Ask before changing source code.

What it does

Tests written without looking at the project end up with the wrong runner, the wrong naming and mocks the team does not use. This command first learns how your repository tests, then writes cases that match.

It aims at behavior and edge cases, not line coverage, and it runs the new tests before it hands them back. A failing test that reveals a real bug is reported, not hidden.

Example

you › /write-tests src/utils/slugify.ts

agent › Added src/utils/slugify.test.ts with 9 cases: accents, repeated dashes, leading spaces, empty string, emoji, 200-character titles.
Run: npm test -- slugify
Result: 8 pass, 1 fails. slugify("  ") returns "-" instead of "". Looks like a bug; I did not touch the source. Fix it?

Questions

Which test framework does it use?
The one already in your repository. It copies the style of the nearest existing tests.
Does it edit my source files?
Only test files. If a test exposes a bug, it reports it and waits for your decision.
  • Add Edge Case Tests

    CommandTesting

    Free
  • Add Regression Test

    CommandTesting

    Free
  • Coverage Gaps

    CommandTesting

    Free
  • E2E Scenario

    CommandTesting

    Free