test(cache): 修复CacheConfigTest边界值测试

- 修改 shouldVerifyCacheManager_withMaximumIntegerTtl 为 shouldVerifyCacheManager_withMaximumAllowedTtl
- 使用正确的最大TTL值(10080分钟,7天)而不是 Integer.MAX_VALUE
- 新增 shouldThrowException_whenTtlExceedsMaximum 测试验证边界检查
- 所有1266个测试用例通过
- 覆盖率: 指令81.89%, 行88.48%, 分支51.55%

docs: 添加项目状态报告
- 生成 PROJECT_STATUS_REPORT.md 详细记录项目当前状态
- 包含质量指标、已完成功能、待办事项和技术债务
This commit is contained in:
Your Name
2026-03-02 13:31:54 +08:00
parent 32d6449ea4
commit 91a0b77f7a
2272 changed files with 221995 additions and 503 deletions

View File

@@ -0,0 +1,183 @@
# Anti-Fake Testing Configuration for Mosquito Project
# Based on 1210 test discoveries
---
# 1. Mock Audit Configuration
mock_audit:
enabled: true
max_mock_ratio: 0.5
banned_mock_patterns:
- "com.mosquito.project.service.*"
- "com.mosquito.project.controller.*"
- "com.mosquito.project.job.*"
require_real_implementations:
- interface: "org.springframework.data.repository.Repository"
implementation: "testcontainers"
- interface: "org.springframework.data.redis.core.RedisTemplate"
implementation: "testcontainers-redis"
- interface: "javax.sql.DataSource"
implementation: "testcontainers-postgres"
allowed_mock_patterns:
- "com.mosquito.project.sdk.*"
- "javax.mail.*"
- "com.thirdparty.*"
---
# 2. Assertion Quality Configuration
assertion_quality:
enabled: true
min_assertions_per_test: 2
required_assertion_types:
- type: "not_null"
min_count: 0
max_ratio: 0.5
description: "null checks should not exceed 50%"
- type: "equals"
min_count: 1
description: "value equality verification"
- type: "business_logic"
min_count: 1
description: "business logic verification"
- type: "side_effect"
min_count: 0
description: "side effect verification"
banned_assertions:
- "assertTrue(true)"
- "assertFalse(false)"
- "assertNotNull(new Object())"
- "assertEquals(1, 1)"
---
# 3. Branch Coverage Enforcement
branch_coverage:
enabled: true
min_coverage: 60
required_branch_types:
- type: "if_else"
priority: 10
- type: "switch_case"
priority: 9
- type: "exception_handler"
priority: 10
- type: "loop_boundary"
priority: 8
- type: "ternary_operator"
priority: 7
auto_generate:
enabled: true
max_tests_per_round: 20
---
# 4. Real Integration Validation
real_integration:
enabled: true
service_startup:
required: true
timeout_seconds: 30
health_check_endpoints:
- "/actuator/health"
- "/api/v1/health"
fail_if_not_running: true
database_validation:
type: "real_write_read"
forbid_in_memory: true
require_transaction_test: true
cache_validation:
type: "real_cache"
forbid_in_memory_cache: true
---
# 5. Mutation Testing Configuration
mutation_testing:
enabled: true
min_detection_rate: 70
mutation_types:
- type: "condition_boundary"
must_detect: true
- type: "null_check_removal"
must_detect: true
- type: "arithmetic_change"
must_detect: true
- type: "return_value_change"
must_detect: false
- type: "exception_swallowing"
must_detect: true
execution:
max_mutations_per_class: 10
timeout_per_mutation: 30
parallel_execution: true
---
# 6. Scoring and Gates
scoring:
mock_audit:
weight: 20
assertion_quality:
weight: 25
branch_coverage:
weight: 25
real_integration:
weight: 15
mutation_testing:
weight: 15
gate:
min_total_score: 80
must_pass:
- mock_audit
- assertion_quality
warning_only:
- mutation_testing
---
# 7. Reporting and Monitoring
reporting:
generate_report: true
report_path: "target/anti-fake-report.html"
log_level: "INFO"
progress_log: ".testing-autonomous/anti-fake-progress.log"
---
# Usage
# 1. Copy this file to: .testing-autonomous/anti-fake.yml
# 2. Enable in Testing-Autonomous:
# @skill testing-autonomous
# optimize --anti-fake-config .testing-autonomous/anti-fake.yml
# 3. View report: open target/anti-fake-report.html

View File

@@ -0,0 +1,307 @@
# 🎯 Testing-Autonomous: 蚊子项目专用配置
# 基于1210个测试经验的优化方案
---
# 1. 目标设定
targets:
# 覆盖率目标(生产级标准)
coverage:
instruction: 85% # 指令覆盖率
branch: 60% # 分支覆盖率
method: 85% # 方法覆盖率
class: 95% # 类覆盖率
# 质量目标
quality:
min_tests_per_class: 5
max_tests_per_class: 50
avg_test_execution_time: 100ms # 毫秒
# 缺陷发现目标
defects:
min_boundary_tests: 10
min_exception_tests: 5
min_concurrency_tests: 3
# 迭代限制
iteration:
max_rounds: 10
coverage_gain_threshold: 2% # 每轮至少提升2%
---
# 2. 自动恢复配置
recovery:
# 超时设置
timeout_threshold: 300s # 5分钟无响应视为卡住
# 恢复策略(基于蚊子项目经验)
strategies:
# 策略1: DTO默认构造函数缺失
dto_noargs_constructor:
trigger: "Cannot construct instance.*no Creators.*exist"
action: "auto_fix_dto"
fix_steps:
- "分析DTO类结构"
- "添加@NoArgsConstructor注解"
- "重新编译验证"
- "重新生成JSON测试"
max_retry: 3
# 策略2: 文件过大拆分
file_too_large:
trigger: "test_file_lines > 500"
action: "split_to_nested"
split_rules:
- "按功能分组(Constructor/Getter/Boundary)"
- "每类最多100个测试"
- "使用@Nested注解"
max_retry: 2
# 策略3: 覆盖率停滞突破
coverage_stalled:
trigger: "coverage_gain < 1% after 100 tests"
action: "switch_strategy"
alternatives:
- name: "focus_branches"
description: "专注分支覆盖"
target: "if/else/switch语句"
- name: "focus_dtos"
description: "专注DTO测试"
target: "com.mosquito.project.dto.*"
- name: "focus_integration"
description: "专注集成测试"
target: "API端到端流程"
- name: "use_testcontainers"
description: "使用真实数据库"
target: "Repository层"
# 策略4: 内存溢出处理
out_of_memory:
trigger: "heap_usage > 90% OR OutOfMemoryError"
action: "reduce_batch_size"
batch_sizes: [100, 50, 25, 10]
cleanup:
- "强制GC"
- "清理临时文件"
- "减少并发线程"
---
# 3. 质量门禁配置
gates:
# 门禁1: 基础检查(必须全部通过)
level1_basic:
compile_check:
command: "mvn compile -q"
must_pass: true
error_message: "编译失败,请检查代码语法"
test_execution:
command: "mvn test -q"
must_pass: true
error_message: "测试执行失败"
# 门禁2: 覆盖率检查
level2_coverage:
instruction_coverage:
metric: "instruction_coverage"
threshold: 85%
must_pass: true
auto_fix: true # 未达标自动触发优化
branch_coverage:
metric: "branch_coverage"
threshold: 60%
must_pass: false # 警告但不阻止
warning_message: "分支覆盖率未达标,建议加强条件测试"
method_coverage:
metric: "method_coverage"
threshold: 85%
must_pass: true
# 门禁3: 质量检查
level3_quality:
test_quality_score:
metric: "test_quality_score"
threshold: 0.7 # 70分
must_pass: true
evaluation_criteria:
- "代码覆盖贡献 > 0.5"
- "分支覆盖贡献 > 0.3"
- "断言数量 >= 2"
- "复杂度适中"
duplicate_test_ratio:
metric: "duplicate_test_ratio"
threshold: 5% # 重复率<5%
must_pass: true
auto_deduplicate: true # 自动去重
low_value_test_ratio:
metric: "low_value_test_ratio"
threshold: 20% # 低价值测试<20%
must_pass: false
warning_message: "低价值测试过多(getter/setter),建议使用参数化测试"
# 门禁4: 缺陷检查(建议性质)
level4_defects:
boundary_test_coverage:
metric: "boundary_test_count"
threshold: 10
must_pass: false
suggestion: "增加边界条件测试(null/空值/极大值/负数)"
exception_test_coverage:
metric: "exception_test_count"
threshold: 5
must_pass: false
suggestion: "增加异常处理测试"
concurrency_test_coverage:
metric: "concurrency_test_count"
threshold: 3
must_pass: false
suggestion: "增加并发安全测试"
---
# 4. 缺口分析配置
gap_analysis:
# 未覆盖代码优先级
priority_rules:
- condition: "class_name contains 'Config'"
priority: 10 # 最高
reason: "配置类影响系统启动"
- condition: "class_name contains 'Service'"
priority: 9
reason: "核心业务逻辑"
- condition: "class_name contains 'Controller'"
priority: 8
reason: "API入口"
- condition: "class_name contains 'Security'"
priority: 10
reason: "安全相关"
- condition: "class_name contains 'Dto' OR class_name contains 'DTO'"
priority: 7
reason: "数据传输对象"
- condition: "complexity > 10"
priority: 9
reason: "复杂度高,风险大"
- condition: "branch_count > 5"
priority: 8
reason: "分支多,测试价值高"
# 忽略规则
ignore_patterns:
- "com.mosquito.project.config.Test*" # 测试配置
- "*.class" # 已编译类
- "target/**" # 构建目录
---
# 5. 蚊子项目特定优化
mosquito_optimizations:
# DTO优化基于发现的问题
dto_optimization:
enabled: true
actions:
- "检查并添加@NoArgsConstructor"
- "验证Jackson兼容性"
- "生成JSON序列化/反序列化测试"
- "测试边界值(null/空字符串/极大值)"
# 分支覆盖优化
branch_optimization:
enabled: true
target_classes:
- "com.mosquito.project.service.*"
- "com.mosquito.project.web.*"
focus_areas:
- "if/else条件分支"
- "switch语句"
- "三元运算符"
- "异常处理路径"
# 配置类优化
config_optimization:
enabled: true
target_classes:
- "com.mosquito.project.config.AppConfig"
- "com.mosquito.project.config.CacheConfig"
- "com.mosquito.project.config.WebMvcConfig"
test_focus:
- "默认值验证"
- "配置加载"
- "边界条件(0/负数/极大值)"
- "异常处理(无效配置)"
---
# 6. 监控和日志
monitoring:
# 进度记录
progress_log: ".testing-autonomous/progress.log"
# 失败模式记录
failure_log: ".testing-autonomous/failures.log"
# 覆盖率历史
coverage_history: ".testing-autonomous/coverage-history.csv"
# 告警设置
alerts:
- condition: "coverage < 50% after 3 rounds"
level: "warning"
message: "覆盖率提升缓慢,建议检查测试策略"
- condition: "test_execution_time > 2 minutes"
level: "warning"
message: "测试执行时间过长,建议优化测试性能"
- condition: "recovery_triggered > 5 times"
level: "error"
message: "多次触发恢复机制,建议人工介入检查"
---
# 7. 预设命令
commands:
# 快速开始
quick_start: |
@skill testing-autonomous
analyze-and-optimize --target 85% --auto-recovery --max-rounds 10
# 仅缺口分析
gap_analysis_only: |
@skill testing-autonomous
analyze-gaps --output report.html
# 质量检查
quality_check: |
@skill testing-autonomous
check-quality --gates all
# 持续优化适合CI/CD
continuous_optimization: |
@skill testing-autonomous
optimize --incremental --coverage-threshold 85% --fail-on-miss
---
# 使用说明
# 1. 复制此文件到项目根目录: .testing-autonomous/config.yml
# 2. 根据项目实际情况调整阈值
# 3. 运行: @skill testing-autonomous
# 4. 执行: optimize-project --config .testing-autonomous/config.yml

182
.testing-autonomous/monitor.sh Executable file
View File

@@ -0,0 +1,182 @@
#!/bin/bash
# 🔍 Testing-Autonomous 实时监控脚本
# 用法: ./monitor.sh [project_path]
PROJECT_PATH=${1:-.}
LOG_FILE="$PROJECT_PATH/.testing-autonomous/progress.log"
COVERAGE_FILE="$PROJECT_PATH/target/site/jacoco/index.html"
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}🔍 Testing-Autonomous 实时监控${NC}"
echo "=================================="
echo "项目路径: $PROJECT_PATH"
echo "=================================="
echo ""
# 检查配置文件
if [ -f "$PROJECT_PATH/.testing-autonomous/config.yml" ]; then
echo -e "${GREEN}✅ 配置文件存在${NC}"
TARGET_COVERAGE=$(grep "instruction:" "$PROJECT_PATH/.testing-autonomous/config.yml" | head -1 | awk '{print $2}' | tr -d '%')
echo "🎯 目标覆盖率: ${TARGET_COVERAGE}%"
else
echo -e "${YELLOW}⚠️ 配置文件不存在,使用默认配置${NC}"
TARGET_COVERAGE=85
fi
echo ""
# 实时监控函数
monitor_progress() {
local last_coverage=0
local round=0
while true; do
clear
echo -e "${BLUE}🔍 Testing-Autonomous 实时监控${NC}"
echo "=================================="
echo "时间: $(date '+%Y-%m-%d %H:%M:%S')"
echo "=================================="
echo ""
# 显示进度日志最近20行
if [ -f "$LOG_FILE" ]; then
echo -e "${BLUE}📊 最新进展:${NC}"
tail -20 "$LOG_FILE" 2>/dev/null | while read line; do
if [[ $line == *"ERROR"* ]] || [[ $line == *"失败"* ]]; then
echo -e "${RED}$line${NC}"
elif [[ $line == *"SUCCESS"* ]] || [[ $line == *"成功"* ]]; then
echo -e "${GREEN}$line${NC}"
elif [[ $line == *"WARNING"* ]] || [[ $line == *"警告"* ]]; then
echo -e "${YELLOW}$line${NC}"
else
echo "$line"
fi
done
echo ""
fi
# 解析当前覆盖率
if [ -f "$COVERAGE_FILE" ]; then
# 从JaCoCo报告中提取覆盖率
COVERAGE=$(grep -o 'ctr2>[0-9]*%' "$COVERAGE_FILE" | head -1 | grep -o '[0-9]*')
if [ ! -z "$COVERAGE" ]; then
echo -e "${BLUE}📈 覆盖率状态:${NC}"
echo "当前: ${COVERAGE}%"
echo "目标: ${TARGET_COVERAGE}%"
# 计算进度条
PROGRESS=$((COVERAGE * 50 / 100)) # 50字符宽度的进度条
BAR=$(printf '%*s' "$PROGRESS" | tr ' ' '█')
REMAINING=$((50 - PROGRESS))
EMPTY=$(printf '%*s' "$REMAINING" | tr ' ' '░')
if [ $COVERAGE -ge $TARGET_COVERAGE ]; then
echo -e "${GREEN}进度: [${BAR}${EMPTY}] ${COVERAGE}% ✅ 已达标${NC}"
else
echo -e "${YELLOW}进度: [${BAR}${EMPTY}] ${COVERAGE}% 🔄 继续优化${NC}"
fi
echo ""
# 显示差距
GAP=$((TARGET_COVERAGE - COVERAGE))
if [ $GAP -gt 0 ]; then
echo -e "${YELLOW}还需提升: ${GAP}%${NC}"
fi
fi
fi
# 检查测试执行状态
if [ -f "$PROJECT_PATH/target/surefire-reports" ]; then
TEST_COUNT=$(find "$PROJECT_PATH/target/surefire-reports" -name "*.txt" | wc -l)
echo -e "${BLUE}🧪 测试统计:${NC}"
echo "测试文件: $TEST_COUNT"
# 统计失败/错误
FAILURES=$(grep -l "FAILURE\|ERROR" "$PROJECT_PATH/target/surefire-reports"/*.txt 2>/dev/null | wc -l)
if [ $FAILURES -gt 0 ]; then
echo -e "${RED}❌ 失败: $FAILURES${NC}"
else
echo -e "${GREEN}✅ 全部通过${NC}"
fi
echo ""
fi
# 检查是否有卡住迹象
if [ -f "$LOG_FILE" ]; then
LAST_UPDATE=$(stat -c %Y "$LOG_FILE" 2>/dev/null || stat -f %m "$LOG_FILE" 2>/dev/null)
CURRENT_TIME=$(date +%s)
TIME_DIFF=$((CURRENT_TIME - LAST_UPDATE))
if [ $TIME_DIFF -gt 300 ]; then # 5分钟无更新
echo -e "${RED}⚠️ 警告: 已超过5分钟无进展可能卡住${NC}"
echo -e "${YELLOW} 自动恢复机制应该已经启动...${NC}"
fi
fi
echo ""
echo -e "${BLUE}==================================${NC}"
echo "按 Ctrl+C 退出监控"
echo -e "${BLUE}==================================${NC}"
# 每5秒刷新一次
sleep 5
done
}
# 快速统计模式
quick_stats() {
echo -e "${BLUE}📊 快速统计${NC}"
echo "=================================="
# 测试数量
if [ -d "$PROJECT_PATH/src/test/java" ]; then
TEST_FILES=$(find "$PROJECT_PATH/src/test/java" -name "*Test.java" | wc -l)
echo -e "测试文件: ${GREEN}$TEST_FILES${NC}"
fi
# 覆盖率
if [ -f "$COVERAGE_FILE" ]; then
COVERAGE=$(grep -o 'ctr2>[0-9]*%' "$COVERAGE_FILE" | head -1 | grep -o '[0-9]*')
if [ ! -z "$COVERAGE" ]; then
if [ $COVERAGE -ge $TARGET_COVERAGE ]; then
echo -e "覆盖率: ${GREEN}${COVERAGE}% ✅${NC}"
else
echo -e "覆盖率: ${YELLOW}${COVERAGE}% 🔄${NC} (目标: ${TARGET_COVERAGE}%)"
fi
fi
fi
# 配置文件状态
if [ -f "$PROJECT_PATH/.testing-autonomous/config.yml" ]; then
echo -e "配置: ${GREEN}✅ 已配置${NC}"
else
echo -e "配置: ${RED}❌ 未配置${NC}"
fi
echo "=================================="
}
# 主逻辑
case "${2:-monitor}" in
monitor)
monitor_progress
;;
stats)
quick_stats
;;
*)
echo "用法: $0 [project_path] [monitor|stats]"
echo ""
echo "示例:"
echo " $0 . monitor # 实时监控当前项目"
echo " $0 . stats # 快速统计"
echo " $0 /path/to/project monitor # 监控指定项目"
exit 1
;;
esac

View File

@@ -0,0 +1,151 @@
# AI生成测试质量门禁配置
# 基于1210个测试的真实经验
---
gates:
# 门禁1: 虚假测试检测
fake_test_detection:
enabled: true
block_on_issue: true
checks:
- name: "no_framework_testing"
description: "禁止测试getter/setter/构造函数"
banned_patterns:
- "should.*whenGet[A-Z].*"
- "should.*whenSet[A-Z].*"
- "shouldConstruct.*"
max_violations: 0
- name: "no_fake_assertions"
description: "禁止虚假断言"
banned_assertions:
- "assertTrue(true)"
- "assertFalse(false)"
- "assertNotNull(new Object())"
- "assertEquals(1, 1)"
max_violations: 0
- name: "meaningful_assertions"
description: "必须有业务意义断言"
min_assertions: 2
min_business_verification: 1
max_null_checks_ratio: 0.5
# 门禁2: 边界条件检查
boundary_coverage:
enabled: true
warning_only: false
requirements:
- type: "numeric"
min_test_values: 5
required_values: ["MIN", "-1", "0", "1", "MAX"]
- type: "string"
min_test_values: 6
required_values: ["null", "empty", "single", "max_length", "unicode", "special"]
- type: "collection"
min_test_values: 4
required_values: ["null", "empty", "single", "max_size"]
- type: "concurrency"
min_tests: 1
required: false
# 门禁3: Mock使用检查
mock_usage:
enabled: true
max_mock_ratio: 0.5
banned_layers:
- "com.mosquito.project.service.*"
- "com.mosquito.project.controller.*"
- "com.mosquito.project.repository.*"
required_real:
- interface: "javax.sql.DataSource"
implementation: "testcontainers"
- interface: "org.springframework.data.redis.connection.RedisConnectionFactory"
implementation: "testcontainers"
# 门禁4: 分支覆盖率
branch_coverage:
enabled: true
min_coverage: 60
auto_generate: true
# 门禁5: 可维护性
maintainability:
enabled: true
naming:
pattern: "should_.*_when_.*"
required_format: "BDD"
structure:
require_given_when_then: true
max_lines_per_test: 30
max_duplicate_code_ratio: 0.1
assertions:
prefer_assertj: true
ban_junit4: true
# 门禁6: 性能基础
performance_baseline:
enabled: true
warning_only: true
requirements:
- type: "execution_time"
max_ms: 100
- type: "large_object"
min_size_mb: 1
test_required: false
- type: "concurrent_load"
min_threads: 2
test_required: false
scoring:
weights:
fake_test_detection: 25
boundary_coverage: 20
mock_usage: 20
branch_coverage: 20
maintainability: 10
performance_baseline: 5
total_thresholds:
A: 90
B: 80
C: 70
D: 60
F: 0
actions:
on_failure:
generate_report: true
suggest_fixes: true
block_merge: true
on_warning:
generate_report: true
allow_merge: true
reporting:
format: "html"
output_path: "target/quality-gates-report.html"
include_suggestions: true
include_examples: true
sections:
- summary
- gate_results
- violations
- suggestions
- examples