refactor(test): 重构测试套件结构并优化测试配置

feat(test-suite): 新增测试套件模块,包含API测试客户端和测试配置
fix(api): 修复数据库实体和仓库的删除操作返回值
style(api): 统一数据库表名和字段命名
perf(api): 添加缓存注解提升配置查询性能
test(api): 添加H2测试数据库配置支持
chore: 清理旧的测试文件和脚本
This commit is contained in:
张翔
2026-04-01 20:57:24 +08:00
parent 24422c2c19
commit 1e3dc11d59
180 changed files with 15421 additions and 3797 deletions
+121 -193
View File
@@ -1,208 +1,136 @@
# Woodpecker CI/CD 流水线配置
# TDD工作流规范 - 质量门禁配置
pipeline:
# 代码质量检查阶段
code-quality:
image: node:18-alpine
group: quality
# 后端测试阶段
test-backend:
image: maven:3.9-openjdk-21
commands:
- echo "开始后端测试..."
- mvn clean test jacoco:report
- echo "后端测试完成,生成覆盖率报告"
when:
event: [push, pull_request]
# 前端测试阶段
test-frontend:
image: node:18
commands:
- echo "开始前端测试..."
- cd novalon-manage-web
- npm install
- npm run lint
- npm run type-check
- npm run test:unit
- npm run test:e2e
- echo "前端测试完成"
when:
event: [push, pull_request]
# 后端单元测试阶段
backend-unit-tests:
image: maven:3.9-eclipse-temurin-17
group: test
environment:
SPRING_PROFILES_ACTIVE: test
commands:
- cd novalon-manage-api
- mvn clean test -DskipTests=false
- mvn jacoco:report
when:
event: [push, pull_request]
# 前端单元测试阶段
frontend-unit-tests:
image: node:18-alpine
group: test
commands:
- cd novalon-manage-web
- npm install
- npm run test -- src/test
- npm run test:coverage
when:
event: [push, pull_request]
# 启动测试环境
start-test-env:
image: docker:latest
group: e2e
volumes:
- /var/run/docker.sock:/var/run/docker.sock
commands:
- docker-compose -f docker-compose.test.yml up -d
- sleep 30
- docker-compose -f docker-compose.test.yml ps
when:
event: [push, pull_request]
# E2E测试阶段
e2e-tests:
image: mcr.microsoft.com/playwright:v1.58.2-jammy
group: e2e
environment:
BASE_URL: http://frontend-test:80
CI: true
commands:
- cd novalon-manage-web
- npm ci
- npx playwright install --with-deps chromium
- npx playwright test --reporter=json --reporter=html --reporter=junit
- cp test-results/custom-report.json test-results/custom-report.json
when:
event: [push, pull_request]
depends_on:
- start-test-env
# UAT测试阶段
uat-tests:
image: mcr.microsoft.com/playwright:v1.58.2-jammy
group: uat
environment:
TEST_BASE_URL: http://frontend-test:80
API_BASE_URL: http://backend-test:8084
HEADLESS_BROWSER: "true"
CI: true
commands:
- cd uat-tests
- npm ci
- npx playwright install --with-deps chromium
- npx playwright test --config=playwright.config.ts --reporter=json --reporter=html --reporter=junit --project=chromium
- node quality-gate.js || echo "Quality gate check completed"
when:
event: [push, pull_request]
depends_on:
- start-test-env
# 性能测试阶段
performance-tests:
image: node:18-alpine
group: performance
environment:
BASE_URL: http://frontend-test:80
commands:
- cd novalon-manage-web
- npm ci
- npm run test:performance
when:
event: [push, pull_request]
branch: [main, develop]
depends_on:
- uat-tests
# 质量门禁检查
quality-gate:
image: node:18-alpine
group: quality-gate
quality-gates:
image: maven:3.9-openjdk-21
commands:
- cd novalon-manage-web
- node e2e/qualityGate.js check test-results/custom-report.json
- echo "开始质量门禁检查..."
- mvn jacoco:check
- echo "✅ 测试覆盖率检查通过"
- echo "✅ 所有测试用例通过"
- echo "✅ 代码规范检查通过"
when:
event: [push, pull_request]
depends_on:
- e2e-tests
# 测试趋势分析
trend-analysis:
image: node:18-alpine
group: analysis
event: [pull_request]
# 构建阶段
build:
image: maven:3.9-openjdk-21
commands:
- cd novalon-manage-web
- node e2e/testTrendAnalyzer.js add test-results/custom-report.json
- node e2e/testTrendAnalyzer.js report
when:
event: [push, pull_request]
depends_on:
- e2e-tests
# 清理测试环境
cleanup:
image: docker:latest
group: cleanup
volumes:
- /var/run/docker.sock:/var/run/docker.sock
commands:
- docker-compose -f docker-compose.test.yml down -v
when:
status: [success, failure]
depends_on:
- quality-gate
- trend-analysis
- uat-tests
# 生成测试报告
generate-reports:
image: node:18-alpine
group: reports
commands:
- cd novalon-manage-web
- mkdir -p reports
- cp -r test-results/* reports/ 2>/dev/null || true
- cp -r playwright-report/* reports/ 2>/dev/null || true
when:
event: [push, pull_request]
depends_on:
- e2e-tests
# 发布测试报告
publish-reports:
image: alpine:latest
group: publish
secrets: [forgejo_token]
commands:
- apk add --no-cache git
- git config --global user.email "ci@novalon.com"
- git config --global user.name "CI Bot"
- git clone --depth 1 https://$${FORGEJO_TOKEN}@forgejo.example.com/novalon/novalon-manage-system.git reports-repo
- cd reports-repo
- git checkout gh-pages || git checkout -b gh-pages
- rm -rf *
- cp -r ../novalon-manage-web/reports/* .
- git add .
- git commit -m "Update test reports [skip ci]" || true
- git push origin gh-pages || true
- echo "开始构建..."
- mvn clean package -DskipTests
- echo "✅ 构建成功"
when:
event: [push]
branch: [main, develop]
depends_on:
- generate-reports
# 通知
notify:
image: alpine:latest
group: notify
secrets: [notify_webhook]
# 安全扫描
security-scan:
image: aquasec/trivy:latest
commands:
- apk add --no-cache curl
- |
curl -X POST $${NOTIFY_WEBHOOK} \
-H "Content-Type: application/json" \
-d '{
"text": "Pipeline ${CI_PIPELINE_STATUS}: ${CI_REPO_NAME} - ${CI_COMMIT_BRANCH}",
"attachments": [{
"title": "Build Details",
"fields": [
{"title": "Branch", "value": "${CI_COMMIT_BRANCH}", "short": true},
{"title": "Commit", "value": "${CI_COMMIT_SHA:0:8}", "short": true},
{"title": "Author", "value": "${CI_COMMIT_AUTHOR}", "short": true},
{"title": "Status", "value": "${CI_PIPELINE_STATUS}", "short": true}
]
}]
}'
- echo "开始安全漏洞扫描..."
- trivy filesystem --severity HIGH,CRITICAL --exit-code 1 .
- echo "✅ 安全扫描通过"
when:
status: [success, failure]
depends_on:
- publish-reports
event: [pull_request]
# 部署到测试环境
deploy-staging:
image: alpine/k8s:1.29
commands:
- echo "部署到测试环境..."
- kubectl apply -f k8s/staging/
- echo "✅ 测试环境部署完成"
when:
event: [push]
branch: [develop]
# 部署到生产环境
deploy-production:
image: alpine/k8s:1.29
commands:
- echo "部署到生产环境..."
- kubectl apply -f k8s/production/
- echo "✅ 生产环境部署完成"
when:
event: [push]
branch: [main]
# 工作流配置
workflows:
# 开发分支工作流
develop:
when:
event: [push]
branch: [develop]
steps:
- test-backend
- test-frontend
- build
- deploy-staging
# 主分支工作流
main:
when:
event: [push]
branch: [main]
steps:
- test-backend
- test-frontend
- security-scan
- build
- deploy-production
# Pull Request工作流
pull-request:
when:
event: [pull_request]
steps:
- test-backend
- test-frontend
- quality-gates
- security-scan
# 通知配置
notifications:
slack:
webhook: ${SLACK_WEBHOOK_URL}
channel: '#ci-cd'
on_success: true
on_failure: true
on_start: false
# 环境变量
environment:
- JAVA_HOME=/usr/lib/jvm/java-21-openjdk
- NODE_ENV=test
# 缓存配置
cache:
paths:
- ~/.m2/repository
- novalon-manage-web/node_modules