feat: 添加测试框架和覆盖率报告功能
feat(测试): 新增Playwright和Vitest测试配置 feat(测试): 添加测试覆盖率报告生成功能 feat(测试): 实现前后端测试脚本集成 fix(测试): 修复测试密码不匹配问题 fix(测试): 修正URL等待策略 fix(测试): 调整错误消息选择器 refactor(测试): 重构测试目录结构 refactor(测试): 优化测试用例组织方式 docs: 更新测试报告文档 docs: 添加测试覆盖率报告模板 ci: 添加Docker测试环境配置 ci: 实现测试自动化脚本 chore: 更新依赖版本 chore: 添加测试相关配置文件
This commit is contained in:
+153
-181
@@ -1,213 +1,185 @@
|
||||
pipeline:
|
||||
build:
|
||||
image: maven:3.9-eclipse-temurin-21
|
||||
commands:
|
||||
- cd novalon-manage-api
|
||||
- mvn clean install -DskipTests -B
|
||||
|
||||
package:
|
||||
image: maven:3.9-eclipse-temurin-21
|
||||
commands:
|
||||
- cd novalon-manage-api
|
||||
- mvn package -DskipTests -B
|
||||
depends_on:
|
||||
- build
|
||||
|
||||
docker-build-gateway:
|
||||
image: docker:latest
|
||||
commands:
|
||||
- cd novalon-manage-api/manage-gateway
|
||||
- docker build -t novalon/manage-gateway:${CI_COMMIT_SHA:0:8} .
|
||||
- docker tag novalon/manage-gateway:${CI_COMMIT_SHA:0:8} novalon/manage-gateway:latest
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
depends_on:
|
||||
- package
|
||||
|
||||
docker-build-app:
|
||||
image: docker:latest
|
||||
commands:
|
||||
- cd novalon-manage-api/manage-app
|
||||
- docker build -t novalon/manage-app:${CI_COMMIT_SHA:0:8} .
|
||||
- docker tag novalon/manage-app:${CI_COMMIT_SHA:0:8} novalon/manage-app:latest
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
depends_on:
|
||||
- package
|
||||
|
||||
deploy-staging:
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- echo "Deploying to staging environment"
|
||||
- echo "Branch: ${CI_COMMIT_BRANCH}"
|
||||
- echo "Commit: ${CI_COMMIT_SHA}"
|
||||
secrets: [ staging_ssh_key ]
|
||||
when:
|
||||
- event: push
|
||||
branch: develop
|
||||
depends_on:
|
||||
- docker-build-gateway
|
||||
- docker-build-app
|
||||
|
||||
deploy-production:
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- echo "Deploying to production environment"
|
||||
- echo "Branch: ${CI_COMMIT_BRANCH}"
|
||||
- echo "Commit: ${CI_COMMIT_SHA}"
|
||||
secrets: [ production_ssh_key ]
|
||||
when:
|
||||
- event: push
|
||||
branch: main
|
||||
depends_on:
|
||||
- docker-build-gateway
|
||||
- docker-build-app
|
||||
|
||||
# ========== 阶段1:快速反馈(提交时) ==========
|
||||
# 后端单元测试(在novalon-manage-api项目中运行)
|
||||
backend-unit-test:
|
||||
image: maven:3.9-eclipse-temurin-21
|
||||
commands:
|
||||
- cd novalon-manage-api
|
||||
- mvn clean verify -B
|
||||
- echo "测试覆盖率报告已生成在 target/site/jacoco/index.html"
|
||||
depends_on:
|
||||
- build
|
||||
when:
|
||||
- event: push
|
||||
|
||||
# SonarQube代码质量检查
|
||||
sonarqube-scan:
|
||||
image: maven:3.9-eclipse-temurin-21
|
||||
commands:
|
||||
- cd novalon-manage-api
|
||||
- mvn clean verify sonar:sonar -Dsonar.host.url=${SONAR_HOST_URL} -Dsonar.login=${SONAR_TOKEN} -B
|
||||
secrets: [ sonar_host_url, sonar_token ]
|
||||
depends_on:
|
||||
- backend-unit-test
|
||||
when:
|
||||
- event: pull_request
|
||||
|
||||
# 前端单元测试(在novalon-manage-web项目中运行)
|
||||
frontend-unit-test:
|
||||
image: node:20
|
||||
# 代码质量检查阶段
|
||||
code-quality:
|
||||
image: node:18-alpine
|
||||
group: quality
|
||||
commands:
|
||||
- cd novalon-manage-web
|
||||
- npm install
|
||||
- npm run test:unit
|
||||
- npm run lint
|
||||
- npm run type-check
|
||||
when:
|
||||
- event: push
|
||||
event: [push, pull_request]
|
||||
|
||||
# ========== 阶段2:全面验证(合并前) ==========
|
||||
# 集成测试(在tests_suite中运行)
|
||||
integration-test:
|
||||
image: python:3.13
|
||||
# 后端单元测试阶段
|
||||
backend-unit-tests:
|
||||
image: maven:3.9-eclipse-temurin-17
|
||||
group: test
|
||||
environment:
|
||||
SPRING_PROFILES_ACTIVE: test
|
||||
commands:
|
||||
- cd tests_suite
|
||||
- pip install -r requirements.txt
|
||||
- playwright install chromium
|
||||
- pytest tests/integration/ -v --tb=short --no-cov
|
||||
depends_on:
|
||||
- build
|
||||
- cd novalon-manage-api
|
||||
- mvn clean test -DskipTests=false
|
||||
- mvn jacoco:report
|
||||
when:
|
||||
- event: pull_request
|
||||
event: [push, pull_request]
|
||||
|
||||
# E2E测试(在tests_suite中运行)
|
||||
e2e-test:
|
||||
image: python:3.13
|
||||
# 前端单元测试阶段
|
||||
frontend-unit-tests:
|
||||
image: node:18-alpine
|
||||
group: test
|
||||
commands:
|
||||
- cd tests_suite
|
||||
- pip install -r requirements.txt
|
||||
- playwright install chromium
|
||||
- pytest tests/e2e/ -v --tb=short --no-cov
|
||||
depends_on:
|
||||
- deploy-staging
|
||||
- cd novalon-manage-web
|
||||
- npm install
|
||||
- npm run test -- src/test
|
||||
- npm run test:coverage
|
||||
when:
|
||||
- event: pull_request
|
||||
event: [push, pull_request]
|
||||
|
||||
# 前端E2E测试(在novalon-manage-web中运行)
|
||||
frontend-e2e-test:
|
||||
image: mcr.microsoft.com/playwright:v1.42.0-jammy
|
||||
# 启动测试环境
|
||||
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 --output=playwright-report
|
||||
environment:
|
||||
NODE_ENV: test
|
||||
CI: true
|
||||
PLAYWRIGHT_HEADLESS: true
|
||||
depends_on:
|
||||
- deploy-staging
|
||||
- npx playwright test --reporter=json --reporter=html --reporter=junit
|
||||
- cp test-results/custom-report.json test-results/custom-report.json
|
||||
when:
|
||||
- event: pull_request
|
||||
event: [push, pull_request]
|
||||
depends_on:
|
||||
- start-test-env
|
||||
|
||||
# 前端E2E测试完整套件(每日运行)
|
||||
frontend-e2e-test-full:
|
||||
image: mcr.microsoft.com/playwright:v1.42.0-jammy
|
||||
# 性能测试阶段
|
||||
performance-tests:
|
||||
image: node:18-alpine
|
||||
group: performance
|
||||
environment:
|
||||
BASE_URL: http://frontend-test:80
|
||||
commands:
|
||||
- cd novalon-manage-web
|
||||
- npm ci
|
||||
- npx playwright install --with-deps chromium
|
||||
- npx playwright test --reporter=json --reporter=html --reporter=junit --output=playwright-report
|
||||
environment:
|
||||
NODE_ENV: test
|
||||
CI: true
|
||||
PLAYWRIGHT_HEADLESS: true
|
||||
depends_on:
|
||||
- deploy-staging
|
||||
- npm run test:performance
|
||||
when:
|
||||
- event: push
|
||||
branch: main
|
||||
event: [push, pull_request]
|
||||
branch: [main, develop]
|
||||
|
||||
# ========== 阶段3:生产验证(部署前) ==========
|
||||
# 性能测试(在tests_suite中运行)
|
||||
performance-test:
|
||||
image: node:20
|
||||
# 质量门禁检查
|
||||
quality-gate:
|
||||
image: node:18-alpine
|
||||
group: quality-gate
|
||||
commands:
|
||||
- npm install -g k6
|
||||
- chmod +x run-performance-tests.sh
|
||||
- ./run-performance-tests.sh http://localhost:8084 http://localhost:3001
|
||||
environment:
|
||||
BASE_URL: http://localhost:8084
|
||||
FRONTEND_URL: http://localhost:3001
|
||||
depends_on:
|
||||
- deploy-staging
|
||||
- cd novalon-manage-web
|
||||
- node e2e/qualityGate.js check test-results/custom-report.json
|
||||
when:
|
||||
- event: tag
|
||||
event: [push, pull_request]
|
||||
depends_on:
|
||||
- e2e-tests
|
||||
|
||||
# 安全测试(在tests_suite中运行)
|
||||
security-test:
|
||||
image: python:3.13
|
||||
# 测试趋势分析
|
||||
trend-analysis:
|
||||
image: node:18-alpine
|
||||
group: analysis
|
||||
commands:
|
||||
- cd tests_suite
|
||||
- pip install -r requirements.txt
|
||||
- pytest tests/security/ -v --no-cov
|
||||
depends_on:
|
||||
- deploy-staging
|
||||
- cd novalon-manage-web
|
||||
- node e2e/testTrendAnalyzer.js add test-results/custom-report.json
|
||||
- node e2e/testTrendAnalyzer.js report
|
||||
when:
|
||||
- event: deployment
|
||||
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
|
||||
|
||||
# 生成测试报告
|
||||
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
|
||||
when:
|
||||
event: [push]
|
||||
branch: [main, develop]
|
||||
depends_on:
|
||||
- generate-reports
|
||||
|
||||
# 通知
|
||||
notify:
|
||||
image: plugins/slack
|
||||
settings:
|
||||
webhook: ${SLACK_WEBHOOK}
|
||||
channel: ci-cd
|
||||
username: woodpecker
|
||||
icon_url: https://woodpecker-ci.org/img/logo.svg
|
||||
image: alpine:latest
|
||||
group: notify
|
||||
secrets: [notify_webhook]
|
||||
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}
|
||||
]
|
||||
}]
|
||||
}'
|
||||
when:
|
||||
- status: [ success, failure ]
|
||||
status: [success, failure]
|
||||
depends_on:
|
||||
- build
|
||||
- package
|
||||
- backend-unit-test
|
||||
- sonarqube-scan
|
||||
- frontend-unit-test
|
||||
- integration-test
|
||||
- e2e-test
|
||||
- frontend-e2e-test
|
||||
- frontend-e2e-test-full
|
||||
- performance-test
|
||||
- security-test
|
||||
- deploy-staging
|
||||
- deploy-production
|
||||
- publish-reports
|
||||
|
||||
Reference in New Issue
Block a user