了解测试 (BDD) ߞ我可以跳过单元测试来重复某些集成测试中已经涵盖的内容吗?
注意:之前有过类似的问题(BDD 和单元测试),但它没有没有真正的直接答案。只需链接到该书即可。
假设我们测试一个个人资料页面。用户提交他的数据。
- 验证失败 - 我们通知他,对象未更新。
- 验证通过——他被重定向到包含提交数据的个人资料页面。对象已更新。凉爽的!
因此,如果我已经测试验证在 BDD 期间正常工作,我是否需要通过单元测试进行双重检查?或者我可以跳过它吗?在这种情况下,正确的做法是什么?为什么?
Note: There was the similar question before ( BDD And Unit Testing ) but it doesn't have an actual straight answer. Just link to the book.
Assume we test a profile page. User submit his data.
- Validation failed — we notify him about it, object not updated.
- Validation passed — he's redirected to profile page with submitted data. Object updated. Cool!
So if I've tested that validations are working properly during BDD do I need to double-check it with Unit Test? Or I can skip it? What will the right thing to do in this case and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
集成测试检查您的部件是否以正确的方式协同工作。
单元测试涵盖每个部分本身的正确功能。
所以,答案有两部分:
Integration test checks your parts are working together in right manner.
Unit test covers right functionality of each part itself.
So, there are two parts of the answer:
如果验证逻辑很简单,请忽略 TDD 教条。您不会从“正确的”单元测试中获得太多好处。
但是,如果验证很复杂,您可能无法在集成测试中测试每个极端情况(或者如果您这样做,测试将需要很长时间才能运行并且很脆弱,即经常由于各种原因而中断,当它们发生故障时,有时很难确定原因。
单元测试受到这些问题的影响要小得多,因此它们可以用来补充集成测试。
If the validation logic is simple, go ahead and ignore the TDD dogma. You won't gain much from "proper" unit tests.
But if the validation is complex, you probably won't be able to test every corner case in an integration tests (or if you do, the tests will take a very long time to run and be fragile, i.e. break often for various reasons, and when they break it will sometimes be hard to determine why.
Unit tests suffer much less from these problems, so they can be useful to complement the integration tests.