SuperAPI AI 工具集

test-scaffold

测试与质量

查看项目

更新于 10-16 06:45

技能介绍

用途:test-scaffold 用于为源代码生成单元测试文件,输出带结构、fixture 和 mocking 模式的测试骨架。它根据项目配置自动判断使用 pytest 还是 Jest。

主要能力:按 AAA(Arrange-Act-Assert)模式组织测试;提供 pytest 与 Jest 两套模板,涵盖 fixture、Mock/patch、参数化测试、异步测试和断言调用等常见写法;给出测试文件命名约定,如 src/utils/validator.py 对应 tests/test_validator.py,src/utils/validator.ts 对应 src/utils/validator.test.ts,src/components/Button.tsx 对应 src/components/Button.test.tsx。

框架检测:检查 pytest.ini、pyproject.toml 中 [tool.pytest] 判定 pytest;检查 jest.config.*、package.json 中 jest 字段判定 Jest;也按扩展名判断,.py 用 pytest,.ts/.js 用 Jest。

使用方式:命令为 /test-scaffold <source-file>。运行测试时,pytest 示例命令包括 pytest -m "not integration and not e2e"、pytest -m "not integration and not e2e" --cov=src --cov-report=term-missing、pytest tests/test_module.py -v;Jest 示例命令包括 npm test、npm test -- --coverage、npm test -- --watch。

测试范围建议:应测试公共函数与方法、正常成功路径、错误条件、边界情况(空值、null、边界值)和输入验证;应对外部 API、数据库调用、文件系统(pytest 用 tmp_path)、时间/日期、随机值进行 mock;不要测试私有实现细节、框架样板代码和第三方库内部。

限制:资料给出覆盖率目标为整体最低 80%、关键路径 100%,并提到生成测试应通过 /quality-check 质量检查并由 /pre-commit 验证;未提供安装依赖、许可证、具体运行平台或价格等信息。