知识卡片

普通读书笔记卡 · 3329.g

测试数据应避免共享魔法ID

理解等级:中级

依赖共享固定 ID 的测试彼此干扰:另一测试删除或改写该记录便会造成无关失败。测试应独立创建所需数据、持有返回 ID,并在结束后清理。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Principles of Software Architecture Modernization》第7章《Proper Service Testing》(源文件:`_epub-src/OPS/ch07.xhtml`,归一化正文 [12686:16893)) - 结论依据:原文用固定用户 ID 被其他测试删除的例子说明数据依赖纠缠。 - 原始内容:To find the right record for your tests, you queried the database and used id: 23475. You ship this test, and it works, but some other engineers delete this id in their test to cover a different scenario. Now you have tests breaking other tests. All this happened because your testing data dependencies were not isolated. Tests were entangled with one another through data. Inefficient testing cycles Testing speed is always relative.