# 🧪 Testgen Guide The `testgen` command generates high-quality unit tests for your existing code files using AI. It's designed to match your project's testing conventions and use the most modern practices for each language. ### Benefits - **Go**: Table-driven `t.Parallel()` matching codebase. - **Python**: Pytest with `@parametrize`. - **C**: Check framework suites. - **C++**: Google Test `EXPECT_*`. - **Boosts coverage**; safe preview. ### Usage Generate comprehensive unit tests for Go/Python/C/C++ files using AI. ```bash grokkit testgen internal/grok/client.go grokkit testgen app.py --yes grokkit testgen foo.c bar.cpp ``` ### Safety Features - **Lang detection** via `internal/linter`. - **Unified diff preview**. - **Y/N confirmation** (`--yes` to auto-confirm). ### Options | Flag | Description | |------|-------------| | `--yes`, `-y` | Skip the confirmation prompt and write tests immediately | | `--model`, `-m` | Override the default model (e.g., `grok-4`) | ### How it Works 1. **Language Detection**: Grokkit detects the language using its internal linter. 2. **Context Analysis**: It reads the source file and any existing test file. 3. **AI Generation**: It sends the source code to Grok with a language-specific system prompt. 4. **Style Matching**: Grok is instructed to use modern idioms and match the project's testing style. 5. **Interactive Diff**: If a test file already exists, it shows a diff of the proposed changes. ### Best Practices - **Start with unit tests**: Test individual functions and methods. - **Run tests immediately**: After `testgen` completes, run `make test` or your language-specific test runner to verify the generated tests. - **Review for accuracy**: AI-generated tests are a great starting point, but always review them to ensure the logic and assertions are correct. - **Coverage**: Use `make test-cover` (for Go) to see how much your new tests have improved your coverage.