您是否应该测试您的 DAO 以及哑层模型?

发布于 2024-12-29 08:32:00 字数 1432 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞慾 2025-01-05 08:32:00

对于这类问题可能有很多意见,所以你不太可能得到确定性;-)

没有实际功能的“薄”或“哑”对象可能不值得自己测试(只测试实际上可能出错的东西)。所以组合单元测试就可以了。

如果模型层对象的复杂性/功能增加,我会为它们添加单元测试,因为更细粒度的本地化测试将更好地定位任何故障,并且更有可能快速运行,因此可以频繁运行。

如果您有任何粗粒度的端到端或“集成”测试,那么这些测试将覆盖两种类型的对象,并且可能发现由于缺乏专用单元测试而遗漏的微不足道的错误...但这是经过计算的风险/判断。

There are probably many opinions on this sort of question, so you are unlikely to get certainty ;-)

'Thin' or 'dumb' objects with no real functionality may not deserve their own tests (only test things that can actually go wrong). So a combined unit test would be OK.

I would add unit tests for the model layer objects if they grow in complexity/functionality, because finer-grained, localised tests will localise any failures better, and are more likely to run fast and therefore be run frequently.

If you have any coarser-grained end-to-end or 'integration' tests, then these will give some coverage of both kinds of object and may pick up trivial errors missed by the absence of dedicated unit tests... but it's a calculated risk / judgement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文