Squashed 'paste-framework/' content from commit 34e8684

git-subtree-dir: paste-framework
git-subtree-split: 34e8684c4bc3cebbe177509f42ab4ef5b5425a7a
This commit is contained in:
zwf
2026-06-02 19:09:22 +08:00
commit 4729698049
107 changed files with 21484 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
# 测试指南
## 测试目录结构
```
tests/
├── conftest.py # 全局 fixtures 和配置
├── unit/ # 单元测试(无外部依赖,可离线运行)
│ ├── test_paste.py # 基础导入和版本
│ ├── test_snow_id.py # 雪花ID生成器
│ ├── test_jwt.py # JWT 令牌(mock
│ ├── test_configure.py # 配置管理(mock
│ ├── test_pagination.py # 分页逻辑
│ ├── test_ustr.py # 字符串工具
│ └── test_udict.py # 字典工具
├── integration/ # 集成测试(需要真实服务)
│ └── test_db.py # 数据库连接测试
└── README.md # 本文件
```
## 运行方式
### 运行所有单元测试(推荐日常使用)
```bash
cd <项目根目录>
pytest tests/unit/ -v
```
### 运行所有测试(含集成测试)
```bash
pytest tests/ -v
```
### 仅运行集成测试
```bash
pytest tests/integration/ -v
```
### 生成覆盖率报告
```bash
pytest tests/unit/ --cov=paste --cov-report=html
open htmlcov/index.html
```
## 编写规范
1. **单元测试**放在 `tests/unit/`,无外部依赖
2. **集成测试**放在 `tests/integration/`,加 `@pytest.mark.integration`
3. 每个测试类以 `Test` 开头,测试方法以 `test_` 开头
4. 使用断言而非 print 验证结果
5. 不依赖外部配置文件或数据库连接