92 lines
2.1 KiB
Markdown
Executable File
92 lines
2.1 KiB
Markdown
Executable File
# BBAV20311 测试套件
|
|
|
|
## 测试结构
|
|
|
|
```
|
|
tests/
|
|
├── conftest.py # pytest配置和fixture
|
|
├── unit/ # 单元测试
|
|
│ ├── agents/
|
|
│ │ └── test_router.py # RouterAgent测试
|
|
│ └── skills/
|
|
│ └── test_gene_identify.py # 技能测试
|
|
├── integration/ # 集成测试
|
|
│ └── test_agent_flow.py # Agent协作流程
|
|
├── e2e/ # 端到端测试
|
|
│ └── test_api.py # API测试
|
|
└── fixtures/ # 测试数据
|
|
```
|
|
|
|
## 运行测试
|
|
|
|
### 安装依赖
|
|
```bash
|
|
pip install -r requirements-test.txt
|
|
```
|
|
|
|
### 运行所有测试
|
|
```bash
|
|
./run_tests.sh
|
|
```
|
|
|
|
### 运行特定测试
|
|
```bash
|
|
# autofill 入口回归检查;不依赖 pytest,适合当前 test4py311 环境
|
|
/home/xia-lab/miniconda3/envs/test4py311/bin/python scripts/check_autofill_regression.py
|
|
|
|
# subfamily review 证据图 scope/manifest 回归检查
|
|
/home/xia-lab/miniconda3/envs/test4py311/bin/python scripts/check_subfamily_evidence_scope.py
|
|
|
|
# 单元测试
|
|
pytest tests/unit -v
|
|
|
|
# 集成测试
|
|
pytest tests/integration -v
|
|
|
|
# E2E测试(需要服务运行)
|
|
pytest tests/e2e -v
|
|
|
|
# 带覆盖率
|
|
pytest tests/ --cov=gfa_core --cov-report=html
|
|
```
|
|
|
|
## 测试类型
|
|
|
|
| 类型 | 速度 | 范围 | 命令 |
|
|
|:---|:---:|:---|:---|
|
|
| 单元测试 | 快(<1s) | 单个函数/类 | `pytest tests/unit` |
|
|
| 集成测试 | 中(<10s) | 模块协作 | `pytest tests/integration` |
|
|
| E2E测试 | 慢(<5min) | 完整流程 | `pytest tests/e2e` |
|
|
|
|
## 编写新测试
|
|
|
|
### 单元测试示例
|
|
```python
|
|
import pytest
|
|
from gfa_core.mas.agents.router import RouterAgent
|
|
|
|
@pytest.mark.unit
|
|
class TestRouterAgent:
|
|
def test_initialization(self):
|
|
agent = RouterAgent(mock_llm)
|
|
assert agent.name == "router"
|
|
```
|
|
|
|
### 集成测试示例
|
|
```python
|
|
import pytest
|
|
|
|
@pytest.mark.integration
|
|
class TestAgentFlow:
|
|
@pytest.mark.asyncio
|
|
async def test_full_flow(self):
|
|
# 测试完整流程
|
|
pass
|
|
```
|
|
|
|
## 测试覆盖率目标
|
|
|
|
- 单元测试: >80%
|
|
- 集成测试: 核心流程覆盖
|
|
- E2E测试: 关键用户场景
|