集成测试实施

发布于 2024-09-25 17:13:17 字数 446 浏览 2 评论 0原文

我有一个三层应用程序

  • Web 应用程序(这里为简单起见,为 ASP.NET MVC)、
  • 业务服务
  • 数据存储库

我知道有四种类型的集成测试:

  • 自上而下、
  • 自下而上的
  • 三明治(前两者的组合)
  • 大爆炸

我知道我会像单元测试一样编写大爆炸测试,但没有任何模拟,所以我也会使用后端数据库...

问题

我不知道如何编写其他类型的集成测试?

  1. 如何编写非 bigbang 类型的集成测试?
  2. 集成测试是否应该等于单元测试,意味着相同数量的测试,但没有模拟的测试?或者这些测试应该测试完全不同的东西?

任何人都可以提供任何信息如何做到这一点(如果有的话)或者这样做是否实际上可行?

I have a three tiered app

  • web app (asp.net mvc for simplicity here),
  • business services
  • data repositories

And I know there are four types of integration tests:

  • top down
  • bottom up
  • sandwich (combination of the top two)
  • big bang

I know I would write big-bang tests just like unit tests but without any mocking so I would employ a backend DB as well...

Questions

I don't know how to write other types of integration tests?

  1. How do I write non-bigbang types of integration tests?
  2. Should integration tests be equal to unit tests meaning same number of tests, but testing without mocks? Or should these tests test something completely different?

Could anybody provide any information how to do this (if at all) or whether it's actually feasible doing it?

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

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

发布评论

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

评论(1

安稳善良 2024-10-02 17:13:17

我建议这样做:

  1. 单元测试/不得进行任何以外部资源
  2. 为中心的集成测试(我想这是自下而上的)。您应该拥有与外部资源非常接近的代码,并且它的唯一责任是与其集成。不要尝试对这些类进行单元测试,而是进行非常集中的测试,以触及真正的资源,而不必处理系统中的其余逻辑。使这个集成类尽可能精简
  3. 完整的系统测试(我猜是大爆炸)。我的意思是 UI 和所有内容(或者 API,如果那是您的端点)。确保您尽可能多地覆盖之前的测试,这更像是简单检查底层部件是否正确连接。

根据您的系统,您可能想也不想在代码顶层补充 3 的集成测试,但不涉及 UI。无论您选择哪种选择,请确保通过单位和医疗机构获得更全面的覆盖。集中的集成测试,因为在顶层测试各种行为具有一定的复杂性,可能很快就会失控。

集成测试是否应该等于单元测试,意味着相同数量的测试,但没有模拟的测试?或者这些测试应该测试完全不同的东西?

正如我在 1 和 1 中提到的2、当那些测试不同的东西时最好。这取决于系统,但我通常期望单元测试的数量是集成测试数量的几倍。对于完整的系统测试,请确保您有足够的资源,以便您可以判断所有部分都已正确连接,但又不能太多,以免变得太复杂而无法测试每个场景。

I suggest doing these:

  1. unit tests / must not hit any external resource
  2. focused integration tests (I guess that'd be bottom up). You should have code that is very close to the external resource, and the sole responsibility of it is integrating with it. Don't try to unit test those classes, instead do very focused tests that hit the real resource and don't have to deal with the rest of the logic in your system. Keep this integration classes as thin as possible
  3. full system tests (I guess big bang). I mean with the UI and everything (or API if that's your endpoint). Make sure you cover as much as possible with the previous tests, and this is more like simple checks the underlying pieces are hooked appropriately.

Depending on your system, you may or not want to complement 3 with integration tests at the top level of the code, but without involving the UI. Regardless of which option you take, make sure to have more comprehensive coverage through unit & focused integration tests, as testing various behavior at the top level have a complexity level that can get out of control very quickly.

Should integration tests be equal to unit tests meaning same number of tests, but testing without mocks? Or should these tests test something completely different?

As I mentioned in 1 & 2, its best when those test different things. This depends on the system, but I'd usually expect the amount of unit tests to be a few times the amount of integration tests. For full system tests, make sure you have enough so that you can tell all the pieces were hooked correctly, but not so much that it becomes too complex to test each scenario.

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