关于 testing-api
面向 API 开发与使用场景的测试技能,覆盖 REST、GraphQL、gRPC 等端点。可检查数据格式、认证、错误处理、限流及服务契约。
主要功能
- 01HTTP 端点测试
- 02请求与响应架构验证
- 03OAuth、JWT 和 API 密钥检查
- 04错误与状态码验证
- 05限流与节流检查
- 06OpenAPI 契约测试
适用场景
- 01开发期间验证 API 行为
- 02检查认证与授权
- 03验证错误响应和配额
- 04测试服务契约与兼容性
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ wojons/ skills --skill testing-api安装后在 Claude Code 中输入/testing-api确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
README.mdreferences/README.mdscripts/example.sh详细介绍
API 测试
测试 REST、GraphQL、gRPC 和其他 API 端点的功能、性能和可靠性。
何时使用
在以下情况下使用此技能:
- 开发或使用 API 服务
- 测试 API 契约和架构
- 验证请求和响应格式
- 测试身份验证和授权
- 检查速率限制和配额
- 验证错误响应和状态码
- 执行服务间的契约测试
我能做什么
- 使用各种 HTTP 方法测试 API 端点
- 验证请求和响应的架构及格式
- 测试身份验证机制(OAuth、JWT、API 密钥)
- 验证错误处理和状态码
- 检查速率限制和流量控制行为
- 测试负载验证和错误消息
- 使用 OpenAPI/Swagger 执行契约测试
- 测试 API 版本控制和向后兼容性
示例
# Test APIs with common tools
npx newman run collection.json # Postman collections
curl -X GET https://api.example.com/users
http GET https://api.example.com/users Authorization:"Bearer token"
# Run API tests with frameworks
npm run test:api # Supertest, Jest
pytest tests/api/ # Python requests/pytest
go test ./api/ # Go httptest
# Test with schema validation
npx ajv validate -s schema.json -d data.json
openapi-test --spec openapi.yaml --base-url https://api.example.com
# Load test APIs
npx autocannon -c 10 -d 30 https://api.example.com/users
wrk -t2 -c100 -d30s https://api.example.com/users
输出格式
API Test Results:
──────────────────────────────
✅ GET /api/users
✓ Returns 200 OK
✓ Returns JSON array
✓ Includes pagination headers
✓ Respects limit parameter
❌ POST /api/users
✗ Missing required fields returns 400
Expected: {"error": "Missing email"}
Received: {"error": "Validation failed"}
⚠️ PUT /api/users/{id}
⚠️ Authentication required but not tested
Authentication Tests:
✓ Valid token returns 200
✗ Invalid token returns 401 (should return 403)
Summary: 15 endpoints tested, 12 passed, 2 failed, 1 skipped
注意事项
- 测试端点支持的所有 HTTP 方法
- 根据 OpenAPI 规范验证响应架构
- 测试边界情况:空数组、空值、大型负载
- 适用时验证 CORS 标头
- 彻底测试身份验证流程
- 考虑对微服务进行契约测试
- 监控 API 响应时间和延迟
评论
支持 Markdown