| name | test |
| description | Generate unit tests or integration tests for existing code. Use when the user wants test coverage for a function, module, or feature that currently has no tests or insufficient tests. |
Test
Write tests for existing code.
Steps
-
Identify the target — Confirm what to test:
- A specific function or class
- A module or file
- An API endpoint or CLI command
-
Read the source — Read the code to be tested carefully. Understand:
- Inputs and expected outputs
- Side effects (file writes, network calls, state mutations)
- Error paths and edge cases
- Any existing tests to avoid duplication
-
Identify the test framework — Check the project for existing test setup:
If no framework exists, suggest the most appropriate one for the stack and ask for confirmation before installing.
-
Write the tests — Cover:
- Happy path: normal expected input → expected output
- Edge cases: empty input, null/undefined, boundary values, max/min
- Error cases: invalid input, failures, exceptions
- Side effects: verify external calls are made (or not made) correctly
-
Run the tests:
-
Report — Show test results and a summary of what's covered.
Principles
- Write tests that test behavior, not implementation details.
- Each test should have one clear assertion focus.
- Use descriptive test names:
should return empty array when input is empty.
- Mock external dependencies (filesystem, network, time) to keep tests fast and deterministic.
- Do not test framework code or third-party libraries.