You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
3.7 KiB
121 lines
3.7 KiB
#!/bin/bash
|
|
|
|
# 统一测试运行脚本
|
|
|
|
set -e
|
|
|
|
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
RESULTS_DIR="$BASE_DIR/results"
|
|
mkdir -p "$RESULTS_DIR"
|
|
|
|
# 日志函数
|
|
log_info() {
|
|
echo -e "\033[32m[INFO]\033[0m $1"
|
|
}
|
|
|
|
log_success() {
|
|
echo -e "\033[32m[SUCCESS]\033[0m $1"
|
|
}
|
|
|
|
log_error() {
|
|
echo -e "\033[31m[ERROR]\033[0m $1"
|
|
}
|
|
|
|
print_header() {
|
|
echo -e "\n\033[36m========================================\033[0m"
|
|
echo -e "\033[36m $1\033[0m"
|
|
echo -e "\033[36m========================================\033[0m\n"
|
|
}
|
|
|
|
# 测试结果统计
|
|
declare -A USER_RESULTS=()
|
|
declare -A PROFILE_RESULTS=()
|
|
|
|
# 运行 User 模块测试
|
|
print_header "User 模块测试"
|
|
if bash "$BASE_DIR/user/test_user.sh" > "$RESULTS_DIR/user_test.log" 2>&1; then
|
|
USER_RESULTS["新增"]="通过"
|
|
USER_RESULTS["查询(新增后)"]="通过"
|
|
USER_RESULTS["更新"]="通过"
|
|
USER_RESULTS["查询(更新后)"]="通过"
|
|
USER_RESULTS["列表查询"]="通过"
|
|
USER_RESULTS["删除"]="通过"
|
|
USER_RESULTS["查询(删除后)"]="通过"
|
|
log_success "User 模块测试全部通过"
|
|
else
|
|
USER_RESULTS["新增"]="失败"
|
|
log_error "User 模块测试失败,查看日志: $RESULTS_DIR/user_test.log"
|
|
fi
|
|
|
|
# 运行 Profile 模块测试
|
|
print_header "Profile 模块测试"
|
|
if bash "$BASE_DIR/profile/test_profile.sh" > "$RESULTS_DIR/profile_test.log" 2>&1; then
|
|
PROFILE_RESULTS["获取"]="通过"
|
|
PROFILE_RESULTS["更新"]="通过"
|
|
PROFILE_RESULTS["查询(更新后)"]="通过"
|
|
PROFILE_RESULTS["修改密码"]="通过"
|
|
log_success "Profile 模块测试全部通过"
|
|
else
|
|
PROFILE_RESULTS["获取"]="失败"
|
|
log_error "Profile 模块测试失败,查看日志: $RESULTS_DIR/profile_test.log"
|
|
fi
|
|
|
|
# 输出测试报告
|
|
echo -e "\n\033[32m========================================\033[0m"
|
|
echo -e "\033[32m 测试报告\033[0m"
|
|
echo -e "\033[32m========================================\033[0m\n"
|
|
|
|
echo -e "\033[1m【User 模块】\033[0m"
|
|
echo "步骤 结果"
|
|
echo "--------------------------------"
|
|
echo "新增 ${USER_RESULTS["新增"]}"
|
|
echo "查询(新增后) ${USER_RESULTS["查询(新增后)"]}"
|
|
echo "更新 ${USER_RESULTS["更新"]}"
|
|
echo "查询(更新后) ${USER_RESULTS["查询(更新后)"]}"
|
|
echo "列表查询 ${USER_RESULTS["列表查询"]}"
|
|
echo "删除 ${USER_RESULTS["删除"]}"
|
|
echo "查询(删除后) ${USER_RESULTS["查询(删除后)"]}"
|
|
|
|
echo -e "\n\033[1m【Profile 模块】\033[0m"
|
|
echo "步骤 结果"
|
|
echo "--------------------------------"
|
|
echo "获取 ${PROFILE_RESULTS["获取"]}"
|
|
echo "更新 ${PROFILE_RESULTS["更新"]}"
|
|
echo "查询(更新后) ${PROFILE_RESULTS["查询(更新后)"]}"
|
|
echo "修改密码 ${PROFILE_RESULTS["修改密码"]}"
|
|
|
|
# 判断总体结果
|
|
USER_PASS=0
|
|
USER_FAIL=0
|
|
for result in "${USER_RESULTS[@]}"; do
|
|
if [ "$result" = "通过" ]; then
|
|
((USER_PASS++))
|
|
else
|
|
((USER_FAIL++))
|
|
fi
|
|
done
|
|
|
|
PROFILE_PASS=0
|
|
PROFILE_FAIL=0
|
|
for result in "${PROFILE_RESULTS[@]}"; do
|
|
if [ "$result" = "通过" ]; then
|
|
((PROFILE_PASS++))
|
|
else
|
|
((PROFILE_FAIL++))
|
|
fi
|
|
done
|
|
|
|
echo -e "\n\033[32m========================================\033[0m"
|
|
echo -e "\033[32m 总体结果\033[0m"
|
|
echo -e "\033[32m========================================\033[0m"
|
|
|
|
echo "User 模块: 通过 $USER_PASS / $((USER_PASS + USER_FAIL)) 项"
|
|
echo "Profile 模块: 通过 $PROFILE_PASS / $((PROFILE_PASS + PROFILE_FAIL)) 项"
|
|
|
|
if [ $USER_FAIL -eq 0 ] && [ $PROFILE_FAIL -eq 0 ]; then
|
|
echo -e "\033[32m所有测试通过!\033[0m\n"
|
|
exit 0
|
|
else
|
|
echo -e "\033[31m存在失败的测试项,请查看日志\033[0m\n"
|
|
exit 1
|
|
fi
|
|
|