agentsclimarketplace

Test gen zh

Skill YuAICode/ai-skills/skills/test-gen-zh

给指定函数或文件生成测试,配合 TDD 习惯。当用户说"帮我生成测试 / 给这个函数写测试 / test-gen-zh / 帮我补测试用例"时触发。bin 探测测试框架,Claude 读实现并按框架惯例生成覆盖正常/边界/错误路径的测试。From its SKILL.md

Install
npx -y skills add YuAICode/ai-skills --skill test-gen-zh

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

3.2 KB, ~1.1k tokens by cl100k_base, as published. Nobody here has run it

test-gen-zh — 测试用例生成

给指定函数或文件自动生成测试,配合 TDD 工作流,覆盖正常路径、边界值、错误路径,而不是凑覆盖率数字。

何时触发

用户说以下任意一种:

  • "帮我生成测试 / 给这个函数写测试 / 补测试用例"
  • "test-gen-zh <文件或函数名>"
  • "这个函数没测试,帮我写一下"
  • "TDD — 先给我写 test"

用法

1. 探测测试框架

bash <skill>/bin/detect-framework.sh [项目目录]
# 输出:go test | jest | vitest | flutter test | pytest | cargo test | unknown
# 默认当前目录;不存在或识别不了均输出 unknown

2. 流程

  1. 探测框架:跑 bin/detect-framework.sh <项目目录> 确认测试框架。若输出 unknown,询问用户用哪个框架后继续。
  2. 读实现:读目标函数 / 文件,理解:
    • 函数签名(参数类型、返回值、可能抛出的错误)
    • 核心逻辑分支
    • 依赖(外部调用、IO、全局状态)
  3. 参照已有测试风格:若项目里有现成测试文件,先读一个做风格参照(命名、断言库、fixture 写法)。
  4. 生成测试:按该框架惯例写测试,三条路径都要覆盖:
    • 正常路径:典型入参 → 预期返回值
    • 边界值:空值、零值、最大/最小、类型边界
    • 错误路径:非法输入、外部依赖失败、超时、panic/exception
  5. 确认可跑:给出完整可执行的测试命令,若有 mock/stub 依赖一并给出。

输出格式

## <文件/函数名> 测试生成报告

**框架**:`<框架>` (由 detect-framework.sh 探测)
**测试文件**:`<建议路径>`

### 覆盖清单
- [ ] 正常路径:<说明>
- [ ] 边界值:<说明>
- [ ] 错误路径:<说明>

### 测试代码

\`\`\`<语言>
<完整可运行的测试代码>
\`\`\`

### 运行方式

\`\`\`bash
<运行命令>
\`\`\`

硬规则

  1. 测真实行为,不是凑覆盖率:每个 case 必须有明确的"验证什么",不写"assert True"这类无效断言。
  2. 不臆造被测代码的行为:拿不准函数在某边界返回什么,先读实现确认,再写断言。不要猜。
  3. 遵循项目已有测试风格:命名、fixture、mock 方式都跟项目已有测试保持一致;若无已有测试则按框架官方惯例。
  4. 依赖隔离:有 IO / 网络 / DB 调用的地方给出 mock/stub/fake 方案,不要生成需要真实环境才能跑的测试。
  5. 输出可直接复制执行:测试代码完整(含 import),运行命令可直接粘贴跑。
  6. 不写任何被测代码:只写测试;若被测函数不存在,说明后让用户先实现。

边界

  • 不依赖外部服务;bin/detect-framework.sh 纯 bash + grep,离线可用。
  • 不修改被测文件。
  • 仅生成测试代码,不执行跑测试(可在"运行方式"里给命令)。
  • 框架识别不了时(unknown)会明确告知并询问用户。

What ships with it: 3 files

6.1 KB alongside SKILL.md, 2 of them executable

bin/

tests/

Keep looking

Skills are one crate of 326,834. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.