Chuyển đến nội dung
Skillpedia
Kiểm thử29k · #9576

api-test-suite-builder

Skill này làm gì

Skill này quét các file route API của bạn và tạo bộ test cho từng endpoint, bao phủ xác thực, kiểm tra dữ liệu, lỗi, phân trang và tải file. Dành cho lập trình viên cần viết test API hoặc bổ sung một bộ test nền.

Khi nào nên dùng

  • ✓Khi bạn thêm một API mới và muốn viết test trước khi viết code.
  • ✓Khi bạn có một API cũ không có test và cần một mốc cơ bản.
  • ✓Khi bạn muốn kiểm tra trước khi phát hành để đảm bảo mọi route có ít nhất một smoke test.

Liên kết skill

https://github.com/alirezarezvani/claude-skills/blob/main/engineering/skills/api-test-suite-builder/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/alirezarezvani/claude-skills/blob/main/engineering/skills/api-test-suite-builder/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tôi cần một bộ test API cho tất cả các route trong ứng dụng Express của tôi, bao gồm lỗi đăng nhập và lỗi kiểm tra dữ liệu.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent nhận diện các route trên các framework phổ biến, rồi viết các file test sẵn sàng chạy, kiểm tra các yêu cầu hợp lệ và không hợp lệ cùng mã lỗi mong đợi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

API Test Suite Builder

Tier: POWERFUL Category: Engineering Domain: Testing / API Quality


Overview

Scans API route definitions across frameworks (Next.js App Router, Express, FastAPI, Django REST) and auto-generates comprehensive test suites covering auth, input validation, error codes, pagination, file uploads, and rate limiting. Outputs ready-to-run test files for Vitest+Supertest (Node) or Pytest+httpx (Python).


Core Capabilities

  • Route detection — scan source files to extract all API endpoints
  • Auth coverage — valid/invalid/expired tokens, missing auth header
  • Input validation — missing fields, wrong types, boundary values, injection attempts
  • Error code matrix — 400/401/403/404/422/500 for each route
  • Pagination — first/last/empty/oversized pages
  • File uploads — valid, oversized, wrong MIME type, empty
  • Rate limiting — burst detection, per-user vs global limits

When to Use

  • New API added — generate test scaffold before writing implementation (TDD)
  • Legacy API with no tests — scan and generate baseline coverage
  • API contract review — verify existing tests match current route definitions
  • Pre-release regression check — ensure all routes have at least smoke tests
  • Security audit prep — generate adversarial input tests

Route Detection

Next.js App Router

# Find all route handlers
find ./app/api -name "route.ts" -o -name "route.js" | sort

# Extract HTTP methods from each route file
grep -rn "export async function\|export function" app/api/**/route.ts | \
  grep -oE "(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)" | sort -u

# Full route map
find ./app/api -name "route.ts" | while read f; do
  route=$(echo $f | sed 's|./app||' | sed 's|/route.ts||')
  methods=$(grep -oE "export (async )?function (GET|POST|PUT|PATCH|DELETE)" "$f" | \
    grep -oE "(GET|POST|PUT|PATCH|DELETE)")
  echo "$methods $route"
done

Express

# Find all router files
find ./src -name "*.ts" -o -name "*.js" | xargs grep -l "router\.\(get\|post\|put\|delete\|patch\)" 2>/dev/null

# Extract routes with line numbers
grep -rn "router\.\(get\|post\|put\|delete\|patch\)\|app\.\(get\|post\|put\|delete\|patch\)" \
  src/ --include="*.ts" | grep -oE "(get|post|put|delete|patch)\(['\"][^'\"]*['\"]"

# Generate route map
grep -rn "router\.\|app\." src/ --include="*.ts" | \
  grep -oE "\.(get|post|put|delete|patch)\(['\"][^'\"]+['\"]" | \
  sed "s/\.\(.*\)('\(.*\)'/\U\1 \2/"

FastAPI

# Find all route decorators
grep -rn "@app\.\|@router\." . --include="*.py" | \
  grep -E "@(app|router)\.(get|post|put|delete|patch)"

# Extract with path and function name
grep -rn "@\(app\|router\)\.\(get\|post\|put\|delete\|patch\)" . --include="*.py" | \
  grep -oE "@(app|router)\.(get|post|put|delete|patch)\(['\"][^'\"]*['\"]"

Django REST Framework

# urlpatterns extraction
grep -rn "path\|re_path\|url(" . --include="*.py" | grep "urlpatterns" -A 50 | \
  grep -E "path\(['\"]" | grep -oE "['\"][^'\"]+['\"]" | head -40

# ViewSet router registration
grep -rn "router\.register\|DefaultRouter\|SimpleRouter" . --include="*.py"

Test Generation Patterns

Auth Test Matrix

For every authenticated endpoint, generate:

Test Case Expected Status
No Authorization header 401
Invalid token format 401
Valid token, wrong user role 403
Expired JWT token 401
Valid token, correct role 2xx
Token from deleted user 401

Input Validation Matrix

For every POST/PUT/PATCH endpoint with a request body:

Test Case Expected Status
Empty body {} 400 or 422
Missing required fields (one at a time) 400 or 422
Wrong type (string where int expected) 400 or 422
Boundary: value at min-1 400 or 422
Boundary: value at min 2xx
Boundary: value at max 2xx
Boundary: value at max+1 400 or 422
SQL injection in string field 400 or 200 (sanitized)
XSS payload in string field 400 or 200 (sanitized)
Null values for required fields 400 or 422

Example Test Files

→ See references/example-test-files.md for details

Generating Tests from Route Scan

When given a codebase, follow this process:

  1. Scan routes using the detection commands above
  2. Read each route handler to understand:
    • Expected request body schema
    • Auth requirements (middleware, decorators)
    • R
Câu hỏi thường gặp

Nó hỗ trợ những framework nào?

Next.js App Router, Express, FastAPI và Django REST, với test viết bằng Vitest cùng Supertest hoặc Pytest cùng httpx.

Nó có kiểm tra giới hạn tần suất không?

Có. Nó bao gồm các kiểm tra giới hạn tần suất như đợt gửi dồn dập và giới hạn theo từng người dùng.

Nó có giúp được trước khi API được viết không?

Có. Nó có thể tạo khung test trước, phù hợp với phát triển theo hướng test.

Chi tiết

Mô tả gốc của tác giả

Use when asked to write API, integration or contract tests for REST endpoints. Builds the suite from the routes: happy paths, auth, validation errors and edge cases per endpoint.

repo: alirezarezvani/claude-skills

Độ phổ biến

Sao GitHub
29k
Vị trí xếp hạng
#9576
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự