safesight-control/docs/unit-test-plan.md

57 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 单元测试开发计划
## 现有测试评估
现有测试全部集中在 `FeatureRegistry.ResolveTemplate`(模板选择算法),其他核心函数覆盖率 **0%**。测试模式存在以下问题:
1. **依赖实现细节**:测试检查具体的模板名(如 `std_face_recognition_stream`),改配置就失败
2. **弱断言**:部分测试只检查错误,不验证输出正确性
3. **缺乏端到端**:没有测试从输入到输出的完整业务流程
4. **无数据隔离**`BuildPipeline` 依赖 SQLite、Agent、Registry难以单独测试
## 测试原则
- 面向功能行为,不面向实现细节
- 验证给定输入产生预期输出
- 测试边界条件(空输入、重复、中文)
- 测试相互独立,可并行运行
## 计划
### P0 — 直接造成过生产问题的函数
| # | 函数 | 测试点 | 状态 |
|---|------|--------|------|
| 1 | `deriveSafeInstanceName` | ASCII名原样返回、中文名生成 hash 前缀、纯数字名原样返回、空字符串 | ⬜ |
| 2 | `cleanSourceNames` | 去重、去空格、空元素过滤、保持顺序 | ⬜ |
| 3 | `BuildPipeline` + `SaveVideoSourceAsset` | 新建视频源、编辑改名、重名冲突 | ⬜ |
### P1 — 核心业务流程
| # | 函数 | 测试点 | 状态 |
|---|------|--------|------|
| 4 | `actionConsoleSave` | 功能选择、批量下发、source 合并 | ⬜ |
| 5 | `actionWizardApply` + `apiWizardDeviceInfo` | 设备选择、通道加载 | ⬜ |
| 6 | `injectIntegrationsIntoConfig` | alarm 注入、storage 注入、无配置时不变 | ⬜ |
### P2 — 辅助函数
| # | 函数 | 测试点 | 状态 |
|---|------|--------|------|
| 7 | `ResolveChannelToSource` | 通道名→视频源名映射、_alarm_后缀剥离 | ⬜ |
| 8 | `SaveVideoSourceAsset` 新签名 | 覆盖签名变更后的旧测试 | ⬜ |
## 已知预存失败(非本次改动引入)
以下 9 个测试在 `/ui/` 前缀剥离后未同步更新断言,需单独修复:
- TestUI_DeviceControlPageShowsLiveActions
- TestUI_ActionDeviceActionCanRenderControlPage
- TestUI_AssetsPageDefinesConfigAssetScope
- TestUI_AssetIntegrationsPageNewModeClearsDetailForm
- TestUI_AssetIntegrationsPageEditModeEnablesFormAndAutofocusesName
- TestUI_AuditAndSystemPagesDefineNewScopes
- TestUI_DeviceAssignmentsPageShowsBoard
- TestUI_DashboardShowsGlobalOperationsSummary
- TestUI_ActionCreateTaskUsesSelectedDeviceCheckboxes