Files
AuthCenterConsoleApp/bash/unit_test.sh

84 lines
3.1 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

#!/bin/bash
# Termux专属 测试用例启动脚本
# 功能:编译代码 + 读取根目录config.ini + 运行ConsoleCmdAutoTest测试类 + 输出测试日志 + 终端环境重置
cd "$(dirname "${BASH_SOURCE[0]}")" || { echo "❌ 目录切换失败"; exit 1; }
BASE_DIR=$(cd .. && pwd)
# ========== 配置项 ==========
# 测试类全限定名
TEST_MAIN_CLASS="cc.winboll.test.ConsoleCmdAutoTest"
# 项目根目录 config.ini 路径(核心修改:固定读取根目录配置文件)
CONFIG_FILE="$BASE_DIR/config.ini"
# 日志输出路径(与测试类中配置的日志目录一致)
TEST_LOG_DIR="$BASE_DIR/logs"
TEST_LOG_FILE="$TEST_LOG_DIR/test_run.log"
# 测试报告路径(匹配测试类中 reports 文件夹路径)
TEST_REPORT_DIR="$BASE_DIR/reports"
TEST_REPORT_FILE="$TEST_REPORT_DIR/test-report.txt"
# JVM 内存配置适配Termux低内存环境
JAVA_OPTS="-Xmx128m -Xms64m"
# 编译脚本路径
BUILD_SH="$BASE_DIR/bash/build_class.sh"
# ========== 前置检查核心新增校验config.ini是否存在 ==========
if [ ! -f "$CONFIG_FILE" ]; then
echo -e "❌ 项目根目录未找到 config.ini 文件!路径:$CONFIG_FILE"
echo -e "请确认 config.ini 已放在项目根目录:$BASE_DIR"
exit 1
fi
echo -e "✅ 已找到配置文件:$CONFIG_FILE"
# 创建日志目录
if [ ! -d "$TEST_LOG_DIR" ]; then
mkdir -p "$TEST_LOG_DIR" || { echo "❌ 日志目录创建失败: $TEST_LOG_DIR"; exit 1; }
fi
# 创建报告目录(确保与测试类路径一致)
if [ ! -d "$TEST_REPORT_DIR" ]; then
mkdir -p "$TEST_REPORT_DIR" || { echo "❌ 报告目录创建失败: $TEST_REPORT_DIR"; exit 1; }
fi
# ========== 配置类路径 ==========
CLASSPATH="$BASE_DIR/runtime"
if [ -d "$BASE_DIR/libs" ]; then
CLASSPATH="$CLASSPATH:$BASE_DIR/libs/*"
fi
# ========== 信号捕获(异常终止处理) ==========
STOP_SIGNAL=0
on_exit() {
STOP_SIGNAL=1
echo -e "\n⚠ 测试进程异常终止!查看日志: $TEST_LOG_FILE"
stty sane
exit 1
}
trap 'on_exit' SIGABRT SIGSEGV SIGILL SIGTERM
# ========== 启动测试用例(核心修改:添加 -config 参数传入配置文件路径) ==========
echo -e "\n🚀 启动测试用例: $TEST_MAIN_CLASS"
echo -e "🔧 加载配置文件: $CONFIG_FILE"
echo -e "📜 测试日志将输出到: $TEST_LOG_FILE"
echo -e "📊 测试报告将保存到: $TEST_REPORT_FILE"
echo -e "=====================================\n"
# 屏蔽^C视觉印记 + 执行测试类(传入-config参数 + 日志重定向
stty -echoctl
java $JAVA_OPTS -cp "$CLASSPATH" "$TEST_MAIN_CLASS" -config:"$CONFIG_FILE" -v -log:ALL &> "$TEST_LOG_FILE"
# ========== 测试结束处理 ==========
if [ $STOP_SIGNAL -eq 0 ]; then
echo -e "\n====================================="
echo "✅ 测试用例执行完成!"
echo "📊 测试报告路径: $TEST_REPORT_FILE"
echo "📜 详细日志路径: $TEST_LOG_FILE"
# 可选:打印报告内容预览
if [ -f "$TEST_REPORT_FILE" ]; then
echo -e "\n📄 报告内容预览:"
head -n 10 "$TEST_REPORT_FILE"
echo "..."
fi
fi
# 重置终端属性,避免残留问题
stty sane
exit $?