了解测试 (BDD) ߞ我可以跳过单元测试来重复某些集成测试中已经涵盖的内容吗?

发布于 2024-12-17 03:21:58 字数 345 浏览 3 评论 0原文

注意:之前有过类似的问题(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 技术交流群。

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

发布评论

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

评论(2

深者入戏 2024-12-24 03:21:58

集成测试检查您的部件是否以正确的方式协同工作。

单元测试涵盖每个部分本身的正确功能。

所以,答案有两部分:

  1. 不,你不应该跳过它。集成测试在整个页面(包括其所有模块)的上下文中测试您的验证。进行验证的模块肯定也应该有对此进行测试的单元测试(就像单元测试一样,单独进行)。
  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:

  1. No, you should not skip it. Integration tests tested your validation in context of the whole page including all its modules. A module that does validation should definitely have Unit Test that test this, as well (in isolation, as Unit Tests do).
  2. You never test same things with Integration tests and with Unit Tests. In integration test you tested the page behaves such and such with certain inputs. In Unit Test you can even ignore you are in a page, if you are testing a self-containing module. Even if that module validates some data and does some decisions. You only Unit Test that validation process and outcome of that decision.
卷耳 2024-12-24 03:21:58

如果验证逻辑很简单,请忽略 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.

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