dingdanquanliucheng/run_tests.bat
2026-06-14 16:20:04 +08:00

139 lines
3.5 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
REM ============================================================
REM 订单全流程管理系统 - 自动化测试执行脚本
REM ============================================================
echo ========================================
echo 订单全流程管理系统 - 自动化测试
echo ========================================
echo.
REM 设置颜色
set GREEN=[92m
set RED=[91m
set YELLOW=[93m
set NC=[0m
REM 检查 Python 环境
echo %YELLOW%检查 Python 环境...%NC%
python --version >nul 2>&1
if errorlevel 1 (
echo %RED%错误: 未找到 Python请先安装 Python 3.8+%NC%
exit /b 1
)
REM 检查 pytest 是否安装
echo %YELLOW%检查 pytest...%NC%
pip show pytest >nul 2>&1
if errorlevel 1 (
echo %YELLOW%安装 pytest...%NC%
pip install pytest pytest-asyncio httpx
)
REM 检查前端依赖
echo %YELLOW%检查前端测试依赖...%NC%
if not exist "e2e\node_modules" (
echo %YELLOW%安装前端测试依赖...%NC%
cd e2e
npm install
npx playwright install chromium
cd ..
)
echo.
echo ========================================
echo 开始执行测试
echo ========================================
echo.
REM ============================================================
REM 后端测试
REM ============================================================
echo %GREEN%[1/4] 执行后端单元测试...%NC%
cd backend
python -m pytest tests/ -v --tb=short -q
set BACKEND_RESULT=%errorlevel%
cd ..
if %BACKEND_RESULT% equ 0 (
echo %GREEN%后端测试通过%NC%
) else (
echo %RED%后端测试失败%NC%
)
echo.
REM ============================================================
REM P0 测试(关键路径)
REM ============================================================
echo %GREEN%[2/4] 执行 P0 关键路径测试...%NC%
cd backend
python -m pytest tests/ -v -m "p0" --tb=short
set P0_RESULT=%errorlevel%
cd ..
if %P0_RESULT% equ 0 (
echo %GREEN%P0 测试通过%NC%
) else (
echo %RED%P0 测试失败%NC%
)
echo.
REM ============================================================
REM 端到端测试
REM ============================================================
echo %GREEN%[3/4] 执行端到端流程测试...%NC%
cd backend
python -m pytest tests/ -v -m "e2e" --tb=short
set E2E_RESULT=%errorlevel%
cd ..
if %E2E_RESULT% equ 0 (
echo %GREEN%E2E 测试通过%NC%
) else (
echo %RED%E2E 测试失败%NC%
)
echo.
REM ============================================================
REM 前端 E2E 测试
REM ============================================================
echo %GREEN%[4/4] 执行前端 E2E 测试...%NC%
cd e2e
npx playwright test --project=chromium
set FRONTEND_RESULT=%errorlevel%
cd ..
if %FRONTEND_RESULT% equ 0 (
echo %GREEN%前端 E2E 测试通过%NC%
) else (
echo %RED%前端 E2E 测试失败%NC%
)
echo.
REM ============================================================
REM 测试报告
REM ============================================================
echo ========================================
echo 测试执行完成
echo ========================================
echo.
echo 后端测试结果: %BACKEND_RESULT%
echo P0 测试结果: %P0_RESULT%
echo E2E 测试结果: %E2E_RESULT%
echo 前端 E2E 结果: %FRONTEND_RESULT%
echo.
echo 查看详细报告:
echo 后端测试: backend\htmlcov\index.html
echo 前端测试: e2e\playwright-report\index.html
echo.
REM 打开测试报告
if exist "e2e\playwright-report\index.html" (
echo %YELLOW%打开前端测试报告...%NC%
start e2e\playwright-report\index.html
)
pause