知识卡片
测试用数据按用例创建并隔离
需要数据库状态的测试,应在准备阶段创建记录并获取本次 ID,再执行断言与清理。独立数据使并行执行与团队共用环境更可靠。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Principles of Software Architecture Modernization》第7章《Proper Service Testing》(源文件:`_epub-src/OPS/ch07.xhtml`,归一化正文 [25205:29321))
- 结论依据:原文将预设魔法 ID 与每次插入并使用返回 ID 对比。
- 原始内容:Bad tests count on the data to already be in the database before they run, like a magic id everyone uses; good tests explicitly set up the data before they run and tear down afterwards. For instance, we could use a testing interface to run code that checks and repairs a magic testing id coded into the Profile Service tests; but what if multiple teams need to run that script at the same time?