dingdanquanliucheng/quick_test.sh

113 lines
3.2 KiB
Bash
Raw Normal View History

2026-06-14 16:20:04 +08:00
#!/bin/bash
# ============================================================
# 订单全流程管理系统 - 快速测试脚本
# ============================================================
# 颜色定义
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}订单全流程管理系统 - 自动化测试${NC}"
echo -e "${GREEN}========================================${NC}"
echo
# 检查 Python 环境
echo -e "${YELLOW}检查 Python 环境...${NC}"
if ! command -v python &> /dev/null; then
echo -e "${RED}错误: 未找到 Python请先安装 Python 3.8+${NC}"
exit 1
fi
# 检查 pytest
echo -e "${YELLOW}检查 pytest...${NC}"
if ! python -c "import pytest" &> /dev/null; then
echo -e "${YELLOW}安装 pytest...${NC}"
pip install pytest pytest-asyncio httpx pytest-cov
fi
echo
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}开始执行测试${NC}"
echo -e "${GREEN}========================================${NC}"
echo
# ============================================================
# 后端测试
# ============================================================
echo -e "${GREEN}[1/3] 执行后端单元测试...${NC}"
cd backend
python -m pytest tests/ -v --tb=short -q
BACKEND_RESULT=$?
cd ..
if [ $BACKEND_RESULT -eq 0 ]; then
echo -e "${GREEN}✓ 后端测试通过${NC}"
else
echo -e "${RED}✗ 后端测试失败${NC}"
fi
echo
# ============================================================
# P0 测试(关键路径)
# ============================================================
echo -e "${GREEN}[2/3] 执行 P0 关键路径测试...${NC}"
cd backend
python -m pytest tests/ -v -m "p0" --tb=short
P0_RESULT=$?
cd ..
if [ $P0_RESULT -eq 0 ]; then
echo -e "${GREEN}✓ P0 测试通过${NC}"
else
echo -e "${RED}✗ P0 测试失败${NC}"
fi
echo
# ============================================================
# 测试覆盖率
# ============================================================
echo -e "${GREEN}[3/3] 生成测试覆盖率报告...${NC}"
cd backend
python -m pytest tests/ --cov=app --cov-report=term-missing -q
COV_RESULT=$?
cd ..
if [ $COV_RESULT -eq 0 ]; then
echo -e "${GREEN}✓ 覆盖率报告生成完成${NC}"
else
echo -e "${RED}✗ 覆盖率报告生成失败${NC}"
fi
echo
# ============================================================
# 测试报告
# ============================================================
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}测试执行完成${NC}"
echo -e "${GREEN}========================================${NC}"
echo
echo "后端测试结果: $BACKEND_RESULT"
echo "P0 测试结果: $P0_RESULT"
echo "覆盖率结果: $COV_RESULT"
echo
echo -e "${YELLOW}查看详细报告:${NC}"
echo " 后端测试: backend/htmlcov/index.html"
echo " 前端测试: e2e/playwright-report/index.html"
echo
# 打开覆盖率报告
if [ -f "backend/htmlcov/index.html" ]; then
echo -e "${YELLOW}打开覆盖率报告...${NC}"
if command -v xdg-open &> /dev/null; then
xdg-open backend/htmlcov/index.html
elif command -v open &> /dev/null; then
open backend/htmlcov/index.html
fi
fi