重构动物认领页面和导航菜单,统一使用SVG图标并优化交互体验

This commit is contained in:
ylweng
2025-09-21 21:12:27 +08:00
parent 467a4ead10
commit 14aca938de
64 changed files with 25067 additions and 18256 deletions

View File

@@ -1,55 +1,390 @@
# 解班客测试文档
# 解班客项目测试文档
## 📋 概述
## 1. 测试概述
本文档详细描述解班客项目的测试策略、测试流程、测试用例设计和质量保证体系。通过全面的测试覆盖,确保系统的稳定性、可靠性和用户体验。
### 1.1 测试目标
确保解班客项目各个模块的功能正确性、性能稳定性、安全可靠性,为产品上线提供质量保障。
## 🎯 测试目标
### 1.2 测试范围
- **后端API服务**:接口功能、性能、安全测试
- **小程序应用**:功能、兼容性、用户体验测试
- **管理后台**:功能、权限、数据一致性测试
- **数据库**:数据完整性、性能、备份恢复测试
- **系统集成**:各模块间集成测试
### 主要目标
- **功能完整性**: 确保所有功能按需求正确实现
- **系统稳定性**: 保证系统在各种条件下稳定运行
- **性能达标**: 满足性能指标和用户体验要求
- **安全可靠**: 确保数据安全和系统安全
- **兼容性**: 支持多平台和多浏览器
### 质量标准
- **代码覆盖率**: ≥ 80%
- **接口测试覆盖率**: 100%
- **核心功能测试覆盖率**: 100%
- **性能指标**: 响应时间 < 2秒
- **可用性**: 99.9%
## 🏗️ 测试架构
### 测试金字塔
### 1.3 测试策略
```mermaid
graph TD
A[UI测试 - 10%] --> B[集成测试 - 20%]
B --> C[单元测试 - 70%]
A[测试策略] --> B[单元测试]
A --> C[集成测试]
A --> D[系统测试]
A --> E[验收测试]
style A fill:#ff9999
style B fill:#99ccff
style C fill:#99ff99
B --> B1[代码覆盖率>80%]
B --> B2[自动化执行]
C --> C1[API集成测试]
C --> C2[数据库集成测试]
D --> D1[功能测试]
D --> D2[性能测试]
D --> D3[安全测试]
E --> E1[用户验收测试]
E --> E2[业务流程验证]
## 2. 测试环境
### 2.1 环境配置
| 环境类型 | 用途 | 配置 | 数据库 |
|---------|------|------|--------|
| 开发环境 | 开发调试 | 本地Docker | MySQL 8.0 |
| 测试环境 | 功能测试 | 测试服务器 | MySQL 8.0 |
| 预发布环境 | 集成测试 | 生产同配置 | MySQL 8.0 |
| 生产环境 | 线上服务 | 高可用集群 | MySQL 8.0主从 |
### 2.2 测试数据管理
```yaml
# 测试数据配置
test_data:
users:
- username: "test_user_001"
email: "test001@example.com"
role: "user"
- username: "test_admin_001"
email: "admin001@example.com"
role: "admin"
trips:
- title: "测试旅行001"
destination: "北京"
start_date: "2024-06-01"
end_date: "2024-06-07"
animals:
- name: "测试动物001"
type: "cat"
location: "北京动物园"
```
### 测试分层
## 3. 测试计划
#### 1. 单元测试 (Unit Testing)
- **目标**: 测试最小可测试单元
- **工具**: Jest, Vitest, JUnit
- **覆盖**: 函数方法组件
### 3.1 测试阶段
#### 2. 集成测试 (Integration Testing)
- **目标**: 测试模块间交互
- **工具**: Supertest, TestContainers
- **覆盖**: API接口数据库交互
```mermaid
gantt
title 测试计划时间线
dateFormat YYYY-MM-DD
section 单元测试
后端单元测试 :ut1, 2024-03-01, 7d
前端单元测试 :ut2, 2024-03-01, 7d
section 集成测试
API集成测试 :it1, after ut1, 5d
数据库集成测试 :it2, after ut1, 3d
section 系统测试
功能测试 :st1, after it1, 10d
性能测试 :st2, after it1, 7d
安全测试 :st3, after it1, 5d
section 验收测试
用户验收测试 :at1, after st1, 7d
```
#### 3. 端到端测试 (E2E Testing)
- **目标**: 测试完整用户流程
- **工具**: Playwright, Cypress
- **覆盖**: 关键业务流程
### 3.2 测试用例设计
#### 3.2.1 后端API测试用例
```javascript
// 用户注册接口测试用例
describe('用户注册API', () => {
test('正常注册流程', async () => {
const userData = {
username: 'testuser001',
email: 'test@example.com',
password: 'Test123456',
phone: '13800138000'
};
const response = await request(app)
.post('/api/auth/register')
.send(userData)
.expect(200);
expect(response.body.code).toBe(0);
expect(response.body.data.user.username).toBe(userData.username);
});
test('重复邮箱注册', async () => {
const response = await request(app)
.post('/api/auth/register')
.send({
username: 'testuser002',
email: 'test@example.com', // 重复邮箱
password: 'Test123456'
})
.expect(400);
expect(response.body.code).toBe(40001);
expect(response.body.message).toContain('邮箱已存在');
});
});
```
#### 3.2.2 小程序功能测试用例
```javascript
// 小程序页面测试
describe('旅行结伴页面', () => {
test('页面正常加载', async () => {
const page = await miniProgram.reLaunch('/pages/trip/list');
await page.waitFor(2000);
const title = await page.$('.page-title');
expect(await title.text()).toBe('旅行结伴');
});
test('创建旅行结伴', async () => {
const page = await miniProgram.navigateTo('/pages/trip/create');
await page.setData({
'form.title': '测试旅行',
'form.destination': '北京',
'form.startDate': '2024-06-01',
'form.endDate': '2024-06-07'
});
await page.tap('.submit-btn');
await page.waitFor(1000);
expect(page.path).toBe('/pages/trip/detail');
});
});
```
## 4. 性能测试
### 4.1 性能指标
| 指标类型 | 目标值 | 测试方法 |
|---------|--------|----------|
| 接口响应时间 | < 500ms | JMeter压测 |
| 页面加载时间 | < 2s | Lighthouse |
| 并发用户数 | 1000+ | 压力测试 |
| 数据库查询 | < 100ms | SQL性能分析 |
| 内存使用率 | < 80% | 系统监控 |
### 4.2 JMeter压测脚本
```xml
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="解班客API压测">
<elementProp name="TestPlan.arguments" elementType="Arguments" guiclass="ArgumentsPanel">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="用户登录压测">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">100</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">50</stringProp>
<stringProp name="ThreadGroup.ramp_time">10</stringProp>
</ThreadGroup>
</hashTree>
</hashTree>
</jmeterTestPlan>
```
### 4.3 Artillery性能测试
```yaml
# artillery-config.yml
config:
target: 'http://localhost:3000'
phases:
- duration: 60
arrivalRate: 10
- duration: 120
arrivalRate: 50
- duration: 60
arrivalRate: 100
scenarios:
- name: "用户注册登录流程"
flow:
- post:
url: "/api/auth/register"
json:
username: "test_{{ $randomString() }}"
email: "{{ $randomString() }}@test.com"
password: "Test123456"
- post:
url: "/api/auth/login"
json:
email: "{{ email }}"
password: "Test123456"
```
## 5. 安全测试
### 5.1 安全测试范围
- **身份认证安全**JWT令牌密码加密
- **授权控制**角色权限接口鉴权
- **数据安全**SQL注入XSS攻击
- **传输安全**HTTPS数据加密
- **系统安全**文件上传敏感信息泄露
### 5.2 OWASP ZAP安全扫描
```yaml
# zap-baseline-scan.yml
version: '3'
services:
zap:
image: owasp/zap2docker-stable
command: zap-baseline.py -t http://host.docker.internal:3000 -r zap-report.html
volumes:
- ./reports:/zap/wrk/:rw
```
### 5.3 安全测试用例
```javascript
// SQL注入测试
describe('SQL注入防护测试', () => {
test('用户名SQL注入', async () => {
const maliciousInput = "admin'; DROP TABLE users; --";
const response = await request(app)
.post('/api/auth/login')
.send({
username: maliciousInput,
password: 'password'
});
// 应该返回错误而不是执行SQL
expect(response.status).toBe(400);
expect(response.body.message).toContain('参数格式错误');
});
});
// XSS攻击测试
describe('XSS防护测试', () => {
test('评论内容XSS过滤', async () => {
const xssPayload = '<script>alert("XSS")</script>';
const response = await request(app)
.post('/api/comments')
.set('Authorization', `Bearer ${token}`)
.send({
content: xssPayload,
tripId: 1
});
expect(response.body.data.content).not.toContain('<script>');
});
});
```
## 6. 测试报告
### 6.1 测试报告模板
```markdown
# 解班客项目测试报告
## 测试概要
- **测试版本**: v1.0.0
- **测试时间**: 2024-03-01 ~ 2024-03-15
- **测试环境**: 测试环境
- **测试人员**: 测试团队
## 测试结果统计
- **总用例数**: 500
- **通过用例**: 485
- **失败用例**: 15
- **通过率**: 97%
## 缺陷统计
- **严重缺陷**: 0
- **一般缺陷**: 8
- **轻微缺陷**: 7
- **建议优化**: 12
## 性能测试结果
- **平均响应时间**: 245ms
- **最大并发用户**: 1200
- **系统稳定性**: 99.8%
## 安全测试结果
- **高危漏洞**: 0
- **中危漏洞**: 2
- **低危漏洞**: 5
## 测试结论
系统整体质量良好,满足上线要求。
```
### 6.2 自动化测试报告
```javascript
// jest.config.js
module.exports = {
collectCoverage: true,
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html'],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
},
reporters: [
'default',
['jest-html-reporters', {
publicPath: './test-reports',
filename: 'test-report.html'
}]
]
};
```
## 7. 总结
### 7.1 测试策略总结
- **全面覆盖**从单元测试到端到端测试的完整覆盖
- **自动化优先**80%以上测试用例实现自动化
- **持续集成**集成到CI/CD流程中
- **质量保证**建立完善的质量门禁机制
### 7.2 测试工具链
- **单元测试**Jest, Vitest
- **集成测试**Supertest, TestContainers
- **E2E测试**Playwright, Cypress
- **性能测试**JMeter, Artillery
- **安全测试**OWASP ZAP, SonarQube
- **测试管理**TestRail, Jira
### 7.3 持续改进
- 定期回顾测试策略和流程
- 持续优化测试用例和自动化脚本
- 加强团队测试技能培训
- 建立测试最佳实践知识库
#### 4. 性能测试 (Performance Testing)
- **目标**: 验证系统性能指标