api-tester
Skill1 starsChanged 3 months agoMITView on GitHub
API 契约测试。根据代码或文档中的真实接口定义生成测试用例,覆盖正常、边界、异常路径,确认环境与授权后执行,输出测试报告。Use to generate and run API tests from the real contract.
6 other projects use a version of this.
Adopted by
Most recently taken up by
- iberi22/skillstheir own version, first seen Oct 15, 2026
- zeroclaw-labs/zeroclaw-skillstheir own version, first seen Sep 24, 2026
- trac3r00/agent-skillstheir own version, first seen Aug 26, 2026
- laolaoshiren/claude-code-skills-zhtheir own version, first seen Jul 2, 2026
- sumulige/sumulige-claudetheir own version, first seen Jan 31, 2026
- onlyoneaman/agent-skillstheir own version, first seen Dec 23, 2025
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- laolaoshiren/claude-code-skills-zh★ 907same name
- zeroclaw-labs/zeroclaw-skills★ 65same name
- onlyoneaman/agent-skills★ 10same name
- sumulige/sumulige-claude★ 2same name
- iberi22/skills★ 0same name
- trac3r00/agent-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository28 other files it gives its agents.
- api-contract-designerSkill
- bug-diagnoserSkill
- cache-governorSkill
- ci-cd-setupSkill
- code-migratorSkill
- code-reviewerSkill
- commit-message-writerSkill
- db-migration-reviewerSkill
- db-schema-designerSkill
- dev-env-troubleshooterSkill
- frontend-debugSkill
- git-workflowSkill
- log-analysisSkill
- meeting-minutesSkill
- natural-chinese-writerSkill
- performance-profilerSkill
- release-note-writerSkill
- requirement-clarifierSkill
- requirements-reviewerSkill
- security-reviewerSkill
- skill-creator-cnSkill
- skill-style-guideSkill
- sql-reviewerSkill
- task-decomposerSkill
- tdd-workflowSkill
- tech-design-writerSkill
- tech-doc-writerSkill
- weekly-reportSkill
The file
Files
API 契约测试
何时使用
- 用户说"给这个接口写测试""测一下这个 API";
- 用户说"帮我验证这个接口通不通""接口改完测一遍";
- 接口文档和实现对不上,想验证真实行为;
- 改完接口要确认没破坏现有调用方;
- 上线前想快速知道哪些接口是好的、哪些是坏的。
使用步骤
第 1 步:找到真实契约
从代码里找,而不是听用户描述:
- 路由定义(Flask/FastAPI/Express/Spring 等框架的路由文件);
- 入参定义(请求体 schema、query 参数、路径参数);
- 出参定义(响应模型、状态码);
- 已有测试或文档,作为补充参考。
如果代码里找不到完整定义,列出缺口,请用户补充或允许按经验推断并标注"推断"。
第 2 步:列出测试用例
每个接口至少三类用例:
| 类型 | 内容 |
| 正常路径 | 合法输入,验证状态码和响应体关键字段 |
| 边界路径 | 空值、极值、超长、类型不符、缺失必填字段 |
| 异常路径 | 未授权、不存在、冲突、服务端错误 |
用例表格式:
| # | 接口 | 场景 | 请求 | 预期状态码 | 预期响应要点 |第 3 步:确认环境与授权
执行前必须和用户确认:
- 测试环境地址(本地、staging、还是线上);
- 认证方式(token、cookie、还是无需认证);
- 测试数据是否允许创建/修改/删除;
- 有没有不能碰的接口或数据。
没确认就不执行。写测试只写测试,不对生产数据下手。
第 4 步:生成并执行测试
- 有 JSON 契约时,用 api_test_gen.py 生成 pytest 骨架(见下面的辅助脚本),再按实际契约核对补全;
- 用项目已有的测试框架(curl 脚本、pytest、Jest 等);
- 测试用例与契约一一对应,能追溯到第 2 步的用例表;
- 执行后把结果和预期对照,失败的标出差异。
第 5 步:输出测试报告
# API 测试报告
## 环境与时间
## 通过/失败统计
## 失败用例明细(接口、请求、实际响应、差异)
## 疑似缺陷(按严重程度排序)
## 建议完整示例
一个可运行的登录接口契约测试见 examples/login-api:自动起服务、跑 5 个用例、出报告,改坏契约就能看到用例变红。
用例设计参考
用例类型、断言要点、框架写法见 references/CASE_DESIGN.md。
输入与输出
- 输入:接口相关代码或文档 + 测试环境信息;
- 输出:测试用例表 + 测试代码/脚本 + 测试报告。
示例
用户输入: "帮我把登录接口测一下。"
契约(从代码确认): POST /api/login,入参 {username, password},成功返回 200 + {token},密码错返回 401。
用例表:
| # | 场景 | 请求 | 预期 |
| 1 | 正常登录 | 正确账号密码 | 200,返回 token |
| 2 | 密码错误 | 正确账号 + 错密码 | 401 |
| 3 | 账号不存在 | 不存在的账号 | 401 或 404(以契约为准) |
| 4 | 缺参 | 只传 username | 400 |
报告节选:
## 通过/失败
4 个用例,3 通过,1 失败
## 失败用例
用例 3:账号不存在返回 404,契约预期 401。响应体提示"账号不存在",存在账号枚举风险。辅助脚本
scripts/api_test_gen.py 把契约 JSON 转成 pytest 测试骨架,支持路径参数、查询参数、请求头、响应字段类型断言:
# 生成契约模板
python skills/api-tester/scripts/api_test_gen.py --new contract.json
# 填好契约后生成测试
python skills/api-tester/scripts/api_test_gen.py contract.json -o tests/test_login.py生成的是骨架,用例和断言按实际契约核对后再执行。运行:API_BASE_URL=<地址> pytest tests/test_login.py。
注意事项
- 契约以代码为准,文档对不上代码时标出来;
- 执行前必须确认环境,默认不碰生产;
- 测试产生的数据要清理,或提前和用户确认保留;
- 失败用例区分"接口 bug"和"测试写错",先复核再下结论。
不适用场景
- 接口还没实现,只能做契约设计(那是另一件事);
- 用户拒绝提供环境信息;
- 第三方外部接口且没有测试账号。
验证方式
- 触发:"给这个接口写测试";
- 跑脚本:有 JSON 契约时用 api_test_gen.py 生成骨架,核对后执行;
- 检查:用例表覆盖正常/边界/异常,执行前有环境确认记录;
- 复核:任选一个失败用例,人工确认差异真实存在。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

