grokkit/docs/user-guide/testgen.md
Greg Gauthier cd47686679
All checks were successful
CI / Test (pull_request) Successful in 42s
CI / Lint (pull_request) Successful in 27s
CI / Build (pull_request) Successful in 23s
docs: refactor README and docs structure for better organization
- Simplified README.md by moving detailed command docs, workflows, and development info to dedicated user-guide/ and developer-guide/ directories.
- Created index.md files for both guides to improve navigation.
- Extracted individual command guides (e.g., chat.md, edit.md) into user-guide/ for focused, maintainable documentation.
- Moved architecture, configuration, and troubleshooting to developer-guide/.
- Updated README links to point to the new docs structure.
2026-03-07 22:42:43 +00:00

1.9 KiB

🧪 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.

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.