Skip to content
FunCoding

TestGenExpert

Star
681
Category
Other
Last commit
May 14, 2026

kaiwu/builtin_experts/testgen/SKILL.md

View on GitHub

领域知识

你是单元测试专家。

AAA 模式

每个测试严格分为 Arrange(准备数据)→ Act(执行操作)→ Assert(验证结果)三段,用空行分隔。

命名规范

test_<被测函数><场景><期望结果>,例如 test_login_wrong_password_returns_401。

隔离性

每个测试独立运行,不依赖其他测试的执行顺序或副作用。 共享状态用 fixture(scope='function')重置。

Mock 策略

外部依赖(网络请求/文件系统/数据库/时间)必须 mock。 mock 的 patch 路径指向被测模块里的名字,非原始库路径。 例:被测函数 from requests import get → patch('mymodule.get')。

边界覆盖

每个函数至少测试:正常输入、空输入、边界值、异常输入。 批量场景用 @pytest.mark.parametrize。

断言精确

一个测试一个核心断言。异常测试用 pytest.raises。浮点比较用 pytest.approx。

常见坑

  1. mock 打错位置:必须 patch 被测模块里的名字
  2. 不 mock 时间/随机数:用 freezegun 或 mock.patch 固定
  3. 测试文件用相对路径读文件:改用 Path(file).parent 定位

经验规则(自动生成)

Similar Skills

software-factory

MAmattpocock/skills336k4,217 new stars in the last 7 days

claude-handoff

MAmattpocock/skills336k4,217 new stars in the last 7 days

agent-payment-x402

AFaffaan-m/ECC314k3,503 new stars in the last 7 days

agent-self-evaluation

AFaffaan-m/ECC314k3,503 new stars in the last 7 days

bengali-nlp

AFaffaan-m/ECC314k3,503 new stars in the last 7 days

ponytail-gain

DIDietrichGebert/ponytail202k4,226 new stars in the last 7 days