catleop/llm-basic/code-review-test-gen
Claude Code and agent skill by catleop/llm-basic
- community
Checking that the SKILL.md file is still in the repository.
针对 PR 中未被测试覆盖的新代码路径,自动生成单元测试并作为 Fix PR 的一部分提交。 内部 skill,由 code-review-act 在满足触发条件时调用。也可单独触发: "generate tests for PR #N", "create unit tests", "add test coverage", "生成测试用例", "自动生成单元测试", "补充测试覆盖"。 Make sure to use this skill whenever the user asks to generate tests, add test coverage, or create unit tests for a PR.
Install
npx vskill@latest install catleop/llm-basic/code-review-test-genSKILL.md
Code Review Test Generation
针对 PR 中新增的业务逻辑代码,自动生成单元测试,提升代码覆盖率。
触发条件
满足以下所有条件时触发:
changed_files中包含业务逻辑文件(非test_*.py/*_test.*/*.test.*/*.spec.*)additions > 20(新增代码超过 20 行)- diff 中包含新增的函数或方法定义(
def/function/const.*=>/class)
输入
diff:PR 的代码变更(来自get_pull_request_files)framework_info:测试框架信息(来自detect_test_framework)owner/repo:仓库标识pr_number:PR 编号
分析步骤
Step 1:识别新增函数/方法
从 diff 中提取所有新增(+ 开头)的函数/方法定义:
Step 2:分析代码路径
对每个新增函数,识别需要测试的路径:
- 正常路径:函数的主要功能(happy path)
- 边界条件:空值、零值、最大值、最小值
- 异常路径:错误输入、抛出异常的场景
- 条件分支:
if/else、try/except、switch的各个分支
Step 3:生成测试代码
根据 framework_info.primary_framework 选择测试模板(参考 references/test-patterns.md)。
Prompt 结构
{ "test_file_path": "tests/test_xxx.py", "test_code": "完整的测试文件内容", "test_count": 数字, "coverage_summary": "覆盖了哪些场景的简要说明" }
Step 4:确定测试文件路径
| 语言 | 原始文件 | 测试文件路径 | |
|---|---|---|---|
| Python | src/services/user.py | tests/test_user.py | |
| Python | app/utils/helpers.py | tests/utils/test_helpers.py | |
| JavaScript | src/utils/format.js | src/utils/format.test.js | |
| TypeScript | src/api/users.ts | src/api/users.spec.ts | |
| Go | pkg/user/service.go | pkg/user/service_test.go |
Step 5:提交测试文件
将生成的测试代码提交到 Fix PR(与自动修复共用同一 PR,或单独创建 test PR):
输出
注意事项
- 不修改业务代码:只生成测试文件,不改动被测试的代码
- 保持幂等:如果测试文件已存在,追加新测试用例而不是覆盖
- Mock 外部依赖:数据库、HTTP、文件系统等必须 mock,避免测试依赖外部环境
- 测试命名规范:
test_<function_name>_<scenario>格式
读取 references/test-patterns.md 了解各语言测试框架模板。
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingLlmLearning/code_review_agent/skills/code-review-test-gen/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/catleop/llm-basic/code-review-test-gen)