Files
张翔 1e3dc11d59 refactor(test): 重构测试套件结构并优化测试配置
feat(test-suite): 新增测试套件模块,包含API测试客户端和测试配置
fix(api): 修复数据库实体和仓库的删除操作返回值
style(api): 统一数据库表名和字段命名
perf(api): 添加缓存注解提升配置查询性能
test(api): 添加H2测试数据库配置支持
chore: 清理旧的测试文件和脚本
2026-04-01 20:57:24 +08:00

7.4 KiB

E2E/UAT 测试套件使用指南

快速开始

1. 环境准备

# 安装Python依赖
pip install -r requirements.txt

# 复制环境变量配置
cp .env.example .env

# 根据实际情况修改 .env 文件

2. 启动开发环境

# 方式1: 使用快速启动脚本
./start_dev.sh

# 方式2: 手动启动
# 启动后端
cd novalon-manage-api
mvn spring-boot:run -Dspring-boot.run.profiles=dev

# 启动前端
cd novalon-manage-web
npm run dev

3. 运行测试

# 运行所有测试
python3 run_tests.py

# 运行特定测试文件
python3 run_tests.py --test-case tests/test_auth.py

# 生成测试报告
python3 run_tests.py --html-report reports/report.html --coverage

# 使用Allure生成详细报告
pytest tests/ --alluredir=reports/allure
allure serve reports/allure

项目结构

test-suite/
├── api/                      # API测试
│   ├── base_api.py          # 基础API客户端
│   ├── auth_api.py          # 认证测试
│   ├── user_api.py          # 用户管理测试
│   ├── role_api.py          # 角色管理测试
│   ├── menu_api.py          # 菜单管理测试
│   ├── config_api.py        # 配置管理测试
│   ├── audit_api.py         # 审计日志测试
│   ├── notice_api.py        # 通知管理测试
│   ├── file_api.py          # 文件管理测试
│   └── dictionary_api.py    # 字典管理测试
├── tests/                    # 集成测试
│   ├── test_auth.py         # 认证集成测试
│   ├── test_user.py         # 用户管理集成测试
│   ├── test_role.py         # 角色管理集成测试
│   ├── test_menu.py         # 菜单管理集成测试
│   ├── test_config.py       # 配置管理集成测试
│   ├── test_audit.py        # 审计日志集成测试
│   ├── test_notice.py       # 通知管理集成测试
│   ├── test_file.py         # 文件管理集成测试
│   ├── test_dictionary.py   # 字典管理集成测试
│   └── test_uat_workflow.py # UAT工作流测试
├── config/                   # 配置文件
│   ├── settings.py          # 测试配置
│   └── __init__.py
├── utils/                    # 工具函数
│   ├── data_generator.py    # 测试数据生成
│   ├── test_data_manager.py # 测试数据管理
│   ├── logger.py            # 日志工具
│   └── assertions.py        # 断言工具
├── reports/                  # 测试报告输出
├── scripts/                  # 辅助脚本
│   ├── start_dev.sh         # 快速启动
│   ├── start_backend.sh     # 启动后端
│   ├── start_frontend.sh    # 启动前端
│   ├── stop_services.sh     # 停止服务
│   ├── configure_h2.sh      # H2配置
│   ├── generate_report.sh   # 生成报告
│   └── run_e2e_uat.sh       # E2E/UAT完整流程
├── .env.example              # 环境变量示例
├── requirements.txt          # Python依赖
├── README.md                 # 本文件
└── TEST_REPORT.md            # 测试报告

测试分类

1. API测试 (api/)

认证测试 (auth_api.py)

  • 用户登录/登出
  • Token生成与验证
  • 权限验证
  • JWT令牌管理

用户管理测试 (user_api.py)

  • 用户CRUD操作
  • 用户状态管理
  • 用户权限验证
  • 批量操作

角色管理测试 (role_api.py)

  • 角色CRUD操作
  • 角色权限分配
  • 角色菜单配置
  • 权限验证

菜单管理测试 (menu_api.py)

  • 菜单CRUD操作
  • 路由配置
  • 菜单权限
  • 动态加载

配置管理测试 (config_api.py)

  • 系统配置CRUD
  • 配置项验证
  • 配置缓存

审计日志测试 (audit_api.py)

  • 登录日志查询
  • 操作日志查询
  • 异常日志查询
  • 日志清理

通知管理测试 (notice_api.py)

  • 通知CRUD操作
  • 通知发送
  • 通知状态

文件管理测试 (file_api.py)

  • 文件上传
  • 文件下载
  • 文件删除
  • 文件列表

字典管理测试 (dictionary_api.py)

  • 字典类型CRUD
  • 字典数据CRUD
  • 字典缓存

2. 集成测试 (tests/)

UAT工作流测试 (test_uat_workflow.py)

  • 完整用户生命周期
  • 完整角色权限流程
  • 完整菜单配置流程
  • 完整系统配置流程
  • 完整审计日志流程

边界条件测试 (test_boundary_conditions.py)

  • 空数据处理
  • 超长数据处理
  • 特殊字符处理
  • 边界值测试

灾难恢复测试 (test_disaster_recovery.py)

  • 数据库故障恢复
  • 服务重启恢复
  • 数据备份恢复

安全测试 (test_security.py)

  • SQL注入防护
  • XSS防护
  • 认证绕过防护
  • 权限提升防护

性能测试 (test_performance.py)

  • 响应时间测试
  • 并发性能测试
  • 压力测试

配置说明

环境变量 (.env)

# API配置
BASE_URL=http://localhost:8084
FRONTEND_URL=http://localhost:3000

# 数据库配置
DATABASE=h2
DATABASE_HOST=localhost
DATABASE_PORT=55432
DATABASE_NAME=manage_system
DATABASE_USERNAME=novalon
DATABASE_PASSWORD=novalon123

# 测试用户凭证
TEST_USERNAME=admin
TEST_PASSWORD=admin123

# 浏览器配置
HEADLESS_BROWSER=true
BROWSER_TYPE=chromium

# 超时配置(毫秒)
REQUEST_TIMEOUT=30000

# 测试模式
TEST_MODE=true
ENV=dev

# 并行测试配置
PARALLEL_TEST=true
NUM_WORKERS=4

# 重试配置
RERUN_FAILED_TESTS=true
RERUN_COUNT=2

# 覆盖率配置
COVERAGE_REPORT=true
COVERAGE_THRESHOLD=80

# 报告配置
HTML_REPORT=reports/report.html
JUNIT_REPORT=reports/junit.xml
ALLURE_REPORT=reports/allure

# 日志配置
LOG_LEVEL=INFO
LOG_FILE=reports/test.log

H2数据库配置

# application-h2-test.yml
spring:
  r2dbc:
    url: r2dbc:h2:mem:///testdb
    username: sa
    password: 
  datasource:
    url: jdbc:h2:mem:testdb
    username: sa
    password: 
  h2:
    console:
      enabled: true
      path: /h2-console
  flyway:
    enabled: false

CI/CD集成

Woodpecker配置

pipeline:
  test-e2e-uat:
    image: python:3.11
    commands:
      - cd test-suite
      - pip install -r requirements.txt
      - python3 run_tests.py --parallel --reruns 2 --coverage
    when:
      event: [push, pull_request]

运行命令

# 本地运行
python3 run_tests.py

# 生成报告
python3 run_tests.py --html-report reports/report.html --coverage

# Allure报告
pytest tests/ --alluredir=reports/allure
allure serve reports/allure

最佳实践

1. 测试编写

  • 使用Fixture管理测试数据
  • 使用Fixture自动清理测试数据
  • 使用参数化测试覆盖多种场景
  • 使用断言验证预期结果

2. 测试运行

  • 提交前运行本地测试
  • 使用并行测试提高效率
  • 失败用例自动重试
  • 生成详细的测试报告

3. 测试维护

  • 定期清理测试数据
  • 更新测试用例覆盖新功能
  • 优化测试性能
  • 增加测试覆盖

故障排查

常见问题

  1. 连接失败

    • 检查后端服务是否启动
    • 检查BASE_URL配置
    • 检查网络连接
  2. 认证失败

    • 检查TEST_USERNAME和TEST_PASSWORD
    • 检查用户是否存在
    • 检查用户状态
  3. 测试超时

    • 增加REQUEST_TIMEOUT
    • 检查服务性能
    • 检查网络延迟
  4. 数据清理失败

    • 检查数据库连接
    • 检查权限配置
    • 手动清理测试数据

技术支持

  • 作者: 张翔
  • 版本: 1.0.0
  • 更新日期: 2026-03-31