yx_speech_to_text_flutter/scripts/run_tests.sh

119 lines
3.4 KiB
Bash
Executable File
Raw Permalink 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.

#!/bin/bash
# YX ASR 测试运行脚本
set -e
echo "🧪 开始运行 YX ASR 测试套件"
echo "================================"
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 函数:打印带颜色的消息
print_message() {
local color=$1
local message=$2
echo -e "${color}${message}${NC}"
}
# 函数:运行测试并检查结果
run_test() {
local test_name=$1
local test_command=$2
print_message $BLUE "📋 运行 $test_name..."
if eval $test_command; then
print_message $GREEN "$test_name 通过"
else
print_message $RED "$test_name 失败"
exit 1
fi
echo ""
}
# 检查 Flutter 是否安装
if ! command -v flutter &> /dev/null; then
print_message $RED "❌ Flutter 未安装或不在 PATH 中"
exit 1
fi
# 获取依赖
print_message $BLUE "📦 获取项目依赖..."
flutter pub get
# 运行不同类型的测试
echo ""
print_message $YELLOW "🔬 开始单元测试"
run_test "单元测试" "flutter test test/unit/ --reporter=expanded"
print_message $YELLOW "🎨 开始组件测试"
run_test "组件测试" "flutter test test/widget/ --reporter=expanded"
print_message $YELLOW "⚡ 开始性能测试"
run_test "性能测试" "flutter test test/performance/ --reporter=expanded"
# 生成覆盖率报告
print_message $YELLOW "📊 生成测试覆盖率报告"
run_test "覆盖率测试" "flutter test --coverage"
# 检查覆盖率报告是否生成
if [ -f "coverage/lcov.info" ]; then
print_message $GREEN "✅ 覆盖率报告已生成: coverage/lcov.info"
# 如果安装了 lcov生成 HTML 报告
if command -v genhtml &> /dev/null; then
print_message $BLUE "📈 生成 HTML 覆盖率报告..."
genhtml coverage/lcov.info -o coverage/html --quiet
print_message $GREEN "✅ HTML 覆盖率报告已生成: coverage/html/index.html"
else
print_message $YELLOW "⚠️ lcov 未安装,跳过 HTML 报告生成"
print_message $YELLOW " 安装方法: brew install lcov (macOS) 或 apt-get install lcov (Ubuntu)"
fi
else
print_message $YELLOW "⚠️ 覆盖率报告未生成"
fi
# 运行集成测试(可选)
if [ "$1" = "--integration" ]; then
print_message $YELLOW "🔗 开始集成测试"
run_test "集成测试" "flutter test integration_test/"
fi
# 代码分析
print_message $YELLOW "🔍 运行代码分析"
run_test "代码分析" "flutter analyze"
# 格式检查
print_message $YELLOW "📝 检查代码格式"
if flutter format --dry-run --set-exit-if-changed .; then
print_message $GREEN "✅ 代码格式正确"
else
print_message $YELLOW "⚠️ 代码格式需要调整"
print_message $BLUE "💡 运行 'flutter format .' 来修复格式问题"
fi
echo ""
print_message $GREEN "🎉 所有测试完成!"
print_message $BLUE "📊 测试结果总结:"
print_message $BLUE " - 单元测试: ✅"
print_message $BLUE " - 组件测试: ✅"
print_message $BLUE " - 性能测试: ✅"
print_message $BLUE " - 代码分析: ✅"
if [ -f "coverage/lcov.info" ]; then
# 计算覆盖率百分比(简单版本)
if command -v lcov &> /dev/null; then
coverage_summary=$(lcov --summary coverage/lcov.info 2>/dev/null | grep "lines" | tail -1)
print_message $BLUE " - 测试覆盖率: $coverage_summary"
fi
fi
echo ""
print_message $GREEN "🚀 项目已准备就绪!"