codity test-gen
Generate AI-powered unit tests for your code changes. Supports automatic test execution and iterative fixing — tests are generated, run locally, and refined until they pass.
Usage
codity test-gen [flags]
Flags
| Flag | Description |
|---|---|
--staged | Generate tests for staged changes (default) |
--all | Generate tests for all uncommitted changes |
--commit <sha> | Generate tests for a specific commit |
--branch <branch> | Generate tests for branch diff |
--write | Write generated test files to disk |
--fix | Run tests and auto-fix failures (implies --write) |
--fix-attempts <int> | Maximum autofix iterations (default: 3) |
--test-cmd <string> | Override the auto-detected test command |
Examples
Generate tests for staged changes (preview only):
codity test-gen --staged
Generate and write test files to disk:
codity test-gen --staged --write
Generate, run, and auto-fix tests:
codity test-gen --staged --fix
Use a custom test command with more fix attempts:
codity test-gen --staged --fix --fix-attempts 5 --test-cmd "pytest -x"
Autofix Loop
When using --fix, the CLI:
- Generates test files and writes them to disk
- Runs the test command locally
- If tests fail, collects failure output and submits to the autofix service
- Applies the fix and re-runs tests
- Repeats up to
--fix-attemptstimes
If all attempts are exhausted and tests still fail, the failing test files are automatically cleaned up.