在 Manus 中运行任何 Skill
一键导入
一键导入
一键在 Manus 中运行任何 Skill
开始使用api-tester
星标568
分支51
更新时间2026年6月17日 11:42
API 自动化测试 - OpenAPI 解析、测试用例生成、集成测试
安装
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
SKILL.md
readonly菜单
API 自动化测试 - OpenAPI 解析、测试用例生成、集成测试
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Changelog 生成器 - 从 Git 历史自动生成 CHANGELOG
数据库迁移助手 - Schema 对比、迁移脚本生成
Git 工作流自动化 - 智能分支管理、提交信息生成、PR 创建
重构顾问 - 识别代码坏味道并提供重构方案
中文 README 生成器 - 先分析项目,再生成面向中文开发者的高质量 README
编程错误消息翻译专家 — 将英文错误消息翻译成中文,解释原因并提供修复方案
| name | api-tester |
| description | API 自动化测试 - OpenAPI 解析、测试用例生成、集成测试 |
当用户要求测试 API、生成测试用例、接口测试、集成测试时激活此技能。
按优先级查找 API 定义:
openapi.yaml、swagger.json)/api/、/routes/、/controllers/)OpenAPI 解析方法:
# 使用 swagger-cli 验证
npx @apidevtools/swagger-cli validate openapi.yaml
# 使用 redocly 提取端点信息
npx @redocly/cli lint openapi.yaml
# 从 OpenAPI 提取所有路径
grep -E '^\s+/' openapi.yaml | awk '{print $2}'
为每个 endpoint 生成三类测试:
根据项目技术栈选择测试框架并生成代码。
策略:
| 策略 | 适用场景 | 工具/方法 |
|---|---|---|
| 固定数据 | 简单接口、确定性测试 | JSON fixture 文件 |
| Faker 随机生成 | 大量测试数据、压力测试 | @faker-js/faker、Faker(Python) |
| 工厂模式 | 复杂对象关系 | factory_boy、fishery |
| 从 Schema 生成 | 基于 OpenAPI 自动生成 | json-schema-faker |
import pytest
# 正常场景
def test_get_users_success(client):
response = client.get("/api/users")
assert response.status_code == 200
assert isinstance(response.json(), list)
# 边界值测试
def test_create_user_empty_name(client):
response = client.post("/api/users", json={"name": ""})
assert response.status_code == 422
# 认证测试
def test_get_users_unauthorized(client):
response = client.get("/api/users", headers={})
assert response.status_code == 401
# 参数化批量测试
@pytest.mark.parametrize("name,expected_status", [
("Alice", 200),
("", 422),
("a" * 500, 422),
(None, 422),
])
def test_create_user_validation(client, name, expected_status):
response = client.post("/api/users", json={"name": name})
assert response.status_code == expected_status
import request from 'supertest';
import app from '../src/app';
describe('GET /api/users', () => {
it('应返回用户列表', async () => {
const res = await request(app).get('/api/users');
expect(res.status).toBe(200);
expect(Array.isArray(res.body)).toBe(true);
});
it('未认证应返回 401', async () => {
const res = await request(app).get('/api/users');
expect(res.status).toBe(401);
});
});
describe('POST /api/users', () => {
it('空名称应返回 422', async () => {
const res = await request(app)
.post('/api/users')
.send({ name: '' });
expect(res.status).toBe(422);
});
it('有效数据应返回 201', async () => {
const res = await request(app)
.post('/api/users')
.send({ name: 'Alice', email: 'alice@test.com' });
expect(res.status).toBe(201);
expect(res.body).toHaveProperty('id');
});
});
#!/bin/bash
BASE_URL="http://localhost:3000/api"
# 正常请求
echo "=== GET /users ==="
curl -s -w "\nHTTP Status: %{http_code}\n" \
-H "Authorization: Bearer *** \
"$BASE_URL/users"
# POST 创建资源
echo "=== POST /users ==="
curl -s -w "\nHTTP Status: %{http_code}\n" \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer *** \
-d '{"name":"Alice","email":"alice@test.com"}' \
"$BASE_URL/users"
# 错误场景 - 空 body
echo "=== POST /users (empty) ==="
curl -s -w "\nHTTP Status: %{http_code}\n" \
-X POST \
-H "Content-Type: application/json" \
-d '{}' \
"$BASE_URL/users"
beforeEach 或 fixture 管理测试数据的初始化和清理