Have Autohand Code inspect public behavior, find edge cases, and add tests that fit the project test style.
Add coverage where behavior is already known
Testing Quality and review Verification Testing
autohand -p "Add focused unit tests for this module using the existing test style"
Focused tests that document behavior and protect future refactors.
Generate unit tests for existing code with Autohand Code is a testing workflow that reads existing code, callers, and edge cases, then adds focused unit tests that match the project style. ### At a glance | Question | Answer | | --- | --- | | Best for | protecting known behavior before a refactor, bug fix, or risky dependency change | | Primary inputs | Target module, function, or public behavior; Known edge cases, bugs, or customer scenarios; Expected test command and preferred test framework | | Autohand Code returns | Focused tests that document behavior and protect future refactors. | | Avoid when | the product behavior is still undecided or the code lacks a stable public contract | ### How Autohand Code handles this workflow 1. Infers the public contract from implementation, callers, and existing tests. 2. Chooses meaningful success, failure, and edge cases. 3. Adds tests using local fixtures, naming, and assertion style. 4. Runs the matching test file and reports uncovered follow-up cases. ### Best inputs - Target module, function, or public behavior - Known edge cases, bugs, or customer scenarios - Expected test command and preferred test framework ### Strong prompt autohand -p "Add focused unit tests for this module using the existing test style" ### Autohand Code CLI options - Run `autohand -p "Add focused unit tests for this module using the existing test style"` for one module or behavior. - Use `--auto-mode` with a clear stop condition when a coverage report names several files to protect. - Use `--yes` only in trusted repositories where running the selected test commands does not need repeated approval. ### Review before accepting Good tests fail for real regressions, avoid incidental snapshots, and explain behavior through clear case names. ### Source and validation signals Autohand AI maintains this workflow as first-party product guidance for Autohand Code. Use the [Autohand CLI Playbook](https://github.com/autohandai/code-cli/blob/main/docs/AUTOHAND_PLAYBOOK.md), [CLI reference](/docs/working-with-autohand-code/cli-reference.html), and [configuration reference](https://github.com/autohandai/code-cli/blob/main/docs/config-reference.md) when choosing between interactive mode, command mode, auto-mode, feature-enabled /goal, /settings, skills, MCP, and permission settings. The related resources below link to product docs and tutorials for the workflow, and the final answer should name repository-specific files, commands, outputs, or docs that a reviewer can verify. ### Frequently asked questions ### What is Generate unit tests for existing code with Autohand Code? Generate unit tests for existing code with Autohand Code is a testing workflow that reads existing code, callers, and edge cases, then adds focused unit tests that match the project style. ### When should a team use Generate unit tests for existing code? Use it before modifying shared code whose behavior is important but weakly covered. ### What evidence should reviewers check for Generate unit tests for existing code? Good tests fail for real regressions, avoid incidental snapshots, and explain behavior through clear case names.
Tutorial Generate Unit Tests for Existing Code Add targeted tests that match existing project style. /docs/tutorials/generate-unit-tests.html Tutorial Add Integration Tests to an API Extend coverage from units to request-level behavior. /docs/tutorials/add-integration-tests.html Tutorial Build a Testing Agent Turn test generation and test repair into a reusable agent workflow. /docs/agent-sdk/tutorials/600-testing-agent.html