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

FlagDescription
--stagedGenerate tests for staged changes (default)
--allGenerate tests for all uncommitted changes
--commit <sha>Generate tests for a specific commit
--branch <branch>Generate tests for branch diff
--writeWrite generated test files to disk
--fixRun 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:

  1. Generates test files and writes them to disk
  2. Runs the test command locally
  3. If tests fail, collects failure output and submits to the autofix service
  4. Applies the fix and re-runs tests
  5. Repeats up to --fix-attempts times

If all attempts are exhausted and tests still fail, the failing test files are automatically cleaned up.