Raw view: Add tests for a file
No invisible, zero-width, or bidi-control characters detected.
---
description: Write tests for a file or function using the project's test framework and conventions, then run them
argument-hint: <path/to/file> [function or behavior to focus on]
allowed-tools: Read, Grep, Glob, Edit, Write, Bash
---
Add tests for `$0`. Focus, if given: $1
Target file:
@$0
Project test configuration (whichever exist):
!`ls package.json pyproject.toml pytest.ini setup.cfg jest.config.* vitest.config.* Cargo.toml go.mod 2>/dev/null || true`
Procedure:
1. Determine the runner and the single-file test command from the config files above (`package.json` scripts, `[tool.pytest]`, etc.). State the command you will use.
2. Find two existing test files nearest to the target with Glob and read them. Copy their conventions exactly: location (colocated vs `tests/`), file naming, imports, fixtures or factories, assertion style, mocking approach, async handling.
3. Check for existing tests of this target with Grep on its exported names; extend rather than duplicate.
4. List the behaviors to test as one-line statements: happy path, each branch, each error path, boundaries (empty, one, max, negative, unicode). If a focus was given, restrict to it.
5. Write one test per behavior, named after the behavior, each arranging its own data. Mock only process boundaries (network, filesystem, clock, randomness), never the module under test.
6. Run the new test file, then the full suite. Show the summary lines.
7. If a test exposes a bug in the target, keep the test, mark it skipped/xfail with a comment naming the bug, and report it. Do not change the target's code.
Output:
## Tests added for `$0`
Runner: `<command>`
Files: <created/modified>
| Behavior | Test | Status |
Suite: <N passed> (before: <N0>)
Bugs found: ...
Not covered and why: ...