api-smoke-testing

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

API Smoke Testing

API 冒烟测试

Verify all API endpoints return healthy responses by combining codebase analysis with HTTP requests.
通过结合代码库分析与HTTP请求,验证所有API端点返回健康响应。

Workflow

工作流程

1. Discover Routes

1. 发现路由

Search the codebase for API route definitions:
Next.js (App Router):
app/api/**/route.ts
Next.js (Pages Router):
pages/api/**/*.ts
Express: Look for
app.get(
,
app.post(
,
router.get(
, etc. Django: Look for
urlpatterns
in
urls.py
FastAPI: Look for
@app.get(
,
@app.post(
, decorators Rails: Look for
routes.rb
Build a list of endpoints with their HTTP methods.
在代码库中搜索API路由定义:
Next.js (App Router):
app/api/**/route.ts
Next.js (Pages Router):
pages/api/**/*.ts
Express: 查找
app.get(
,
app.post(
,
router.get(
, 等 Django: 查找
urls.py
中的
urlpatterns
FastAPI: 查找
@app.get(
,
@app.post(
, 等装饰器 Rails: 查找
routes.rb
构建包含HTTP方法的端点列表。

2. Ensure Server is Running

2. 确保服务器运行

Check terminal files for a running dev server. If none found, start one.
检查终端文件是否有运行中的开发服务器。如果未找到,则启动一个。

3. Hit Every Endpoint

3. 访问每个端点

For each route:
bash
curl -s -o /dev/null -w "%{http_code}" -X <METHOD> http://localhost:<PORT><PATH>
For endpoints that require a body (POST/PUT/PATCH), send a minimal valid JSON:
bash
curl -s -o /dev/null -w "%{http_code}" -X POST http://localhost:<PORT><PATH> \
  -H "Content-Type: application/json" \
  -d '{}'
对于每个路由:
bash
curl -s -o /dev/null -w "%{http_code}" -X <METHOD> http://localhost:<PORT><PATH>
对于需要请求体的端点(POST/PUT/PATCH),发送一个最小的有效JSON:
bash
curl -s -o /dev/null -w "%{http_code}" -X POST http://localhost:<PORT><PATH> \
  -H "Content-Type: application/json" \
  -d '{}'

4. Classify Results

4. 分类结果

StatusMeaning
200-299OK
301/302Redirect (OK)
400Bad request (expected for empty POST bodies)
401/403Auth required (expected for protected routes)
404Route not found (BUG — route exists in code but not served)
500Server error (BUG)
000/timeoutServer not responding (BUG)
状态码含义
200-299正常
301/302重定向(正常)
400错误请求(空POST请求体时为预期情况)
401/403需要认证(受保护路由的预期情况)
404路由未找到(BUG——代码中存在路由但未提供服务)
500服务器错误(BUG)
000/超时服务器无响应(BUG)

5. Report

5. 生成报告

API Smoke Test Results:
  Tested: 15 endpoints
  Passed: 12
  Auth required: 2 (GET /api/user, POST /api/settings)
  Errors:
    500 — POST /api/webhooks/stripe (TypeError: Cannot read property 'id' of undefined)
    404 — GET /api/v2/health (route defined but not mounted)
API 冒烟测试结果:
  测试端点: 15 个
  通过: 12 个
  需要认证: 2 个 (GET /api/user, POST /api/settings)
  错误:
    500 — POST /api/webhooks/stripe (TypeError: Cannot read property 'id' of undefined)
    404 — GET /api/v2/health (route defined but not mounted)

6. Fix Errors

6. 修复错误

For 500 errors, read the terminal output for the stack trace and fix the root cause. For 404s, check that the route file is in the correct location and properly exported.
对于500错误,查看终端输出中的堆栈跟踪并修复根本原因。对于404错误,检查路由文件是否在正确位置并已正确导出。