Habilidades api-testing
🧪

api-testing

Baixo Risco

为 FastAPI 和 React 编写 API 测试

开发者在为他们的 API 创建可靠测试时面临困难。此技能提供了使用 pytest 和 Playwright 进行单元测试、集成测试和端到端测试的即用模式。

Suporta: Claude Codex Code(CC)
📊 69 Adequado
1

Baixar o ZIP da skill

2

Upload no Claude

Vá em Configurações → Capacidades → Skills → Upload skill

3

Ative e comece a usar

Testar

A utilizar "api-testing". 为 GET /api/v1/students 端点编写测试

Resultado esperado:

  • 测试带分页的学生列表返回正确数据
  • 测试未经身份验证的请求返回 401
  • 测试非管理员用户只能看到活跃学生

A utilizar "api-testing". 为 FastAPI 测试创建 pytest fixtures

Resultado esperado:

  • 带自动清理的 db_session fixture
  • 带数据库覆盖的 TestClient fixture
  • 带哈希密码的 test_user fixture
  • 带 JWT token 的 auth_headers fixture

A utilizar "api-testing". 为 React 端到端测试设置 Playwright

Resultado esperado:

  • 带 baseURL 和重试的 playwright.config.ts
  • 带 createStudent 方法的 StudentsPage 页面对象
  • 带 beforeEach login 的 test.describe 块

Auditoria de Segurança

Baixo Risco
v6 • 1/21/2026

All static findings are false positives. The scanner incorrectly flagged regex functions (re.match/re.search) as weak cryptographic algorithms. Environment variable references and hardcoded URLs are documentation examples for test configuration, not credential exposure. The skill follows standard API testing patterns with no malicious behavior.

3
Arquivos analisados
1,597
Linhas analisadas
0
achados
6
Total de auditorias
Nenhum problema de segurança encontrado
Auditado por: claude Ver Histórico de Auditoria →

Pontuação de qualidade

45
Arquitetura
100
Manutenibilidade
87
Conteúdo
21
Comunidade
90
Segurança
87
Conformidade com especificações

O Que Você Pode Construir

为新的 FastAPI 端点添加测试

为带有身份验证和验证的新学生 CRUD 端点创建 pytest fixtures 和集成测试。

为 React 仪表板设置端到端测试

使用页面对象模型配置 Playwright,用于测试登录、创建学生和筛选等用户流程。

将测试添加到 CI/CD 管道

创建 GitHub Actions 工作流,在每次推送时运行带覆盖率的后端 pytest 和前端 Playwright 测试。

Tente Estes Prompts

基本 API 测试请求
为 GET /api/v1/users/{user_id} 的 FastAPI 端点编写 pytest 测试,该端点返回用户详情。包括成功情况和 404 未找到的测试。
带身份验证的集成测试
为 POST /api/v1/students 端点创建集成测试。使用带 Bearer token 身份验证的 TestClient fixture。测试创建成功、未授权访问和验证错误。
模块的完整测试套件
为费用 API 生成完整的测试模块,包括 conftest.py fixtures、calculate_fee 函数的单元测试以及所有费用端点的集成测试。
使用页面对象模型的端到端测试
使用页面对象模型为学生管理功能编写 Playwright 端到端测试。包括登录、创建学生、按年级筛选和查看学生详情的测试。

Melhores Práticas

  • 使用 pytest fixtures 进行共享设置以避免代码重复
  • 测试正常路径和边缘情况,包括验证错误
  • 为每个测试函数使用新数据库隔离测试
  • 在 Playwright 中使用页面对象模型以实现可维护的选择器

Evitar

  • 在单个测试函数中硬编码测试数据而不是使用 fixtures
  • 使测试依赖于执行顺序或其他测试
  • 在测试配置中使用生产数据库凭据
  • 跳过测试运行之间的测试数据清理

Perguntas Frequentes

此技能支持哪些测试框架?
此技能支持用于 Python/FastAPI 后端的 pytest 和用于 TypeScript/React 前端的 Playwright。它还涵盖 Cypress 作为替代的端到端测试框架。
如何测试需要身份验证的端点?
创建一个使用 create_access_token 生成 JWT token 的 auth_headers fixture。将这些 headers 传递给 TestClient 请求以访问需要身份验证的端点。
此技能可以为 GraphQL API 生成测试吗?
不可以,此技能专注于使用 FastAPI 的 REST API。对于 GraphQL,您需要不同的技能或调整 pytest 模式以使用 graphene-test-client。
如何在 CI 中运行测试?
使用提供的 GitHub Actions 工作流示例。它设置 Python/Node、安装依赖项、运行带覆盖率的 pytest,并可选地运行 Playwright 测试。
我应该为测试使用内存数据库吗?
是的,使用带 StaticPool 的 SQLite 以实现隔离和速度。conftest.py 示例展示了如何创建为每个测试重置的内存数据库。
我应该追求什么样的覆盖率目标?
针对核心模块追求 80%+ 的覆盖率,针对关键路径(如身份验证、支付处理和数据验证)追求 90%+ 的覆盖率。

Detalhes do Desenvolvedor

Estrutura de arquivos

📁 scripts/

📄 verify.py

📄 SKILL.md