简体   繁体   English

当集成测试已经存在时,有人可以举一个单元测试增加价值的具体例子吗?

[英]Can someone give a concrete example of a unit test adding value when integration tests already exist?

Let's assume we are not doing TDD (for which unit tests are obviously part and parcel), and have integration tests for all the use cases. 假设我们没有进行TDD(显然,单元测试是TDD的一部分),并且针对所有用例进行了集成测试。

The integration tests assume assume a certain input and validate the output is as expected. 集成测试假设假设输入一定并验证输出是否符合预期。

My thinking is that adding a unit test for a method that is traversed in an integration test, using the same data as would exist in the method in the integration test , would not expose any additional bugs. 我的想法是, 使用与集成测试中的方法相同的数据为集成测试中遍历的方法添加一个单元测试 ,不会暴露任何其他错误。

That would lead to the conclusion that provided you have suffcient integration tests you do not then need to unit test the same code. 得出的结论是,只要您有足够的集成测试,就不需要对相同的代码进行单元测试。

So, can someone give a concrete example where a unit test could expose a bug in the above scenario? 因此,有人可以举一个具体的例子,说明在上述情况下单元测试可能会暴露一个错误吗?

Integration tests can be seen as a form of Acceptance Testing . 集成测试可以看作是验收测试的一种形式。 They ensure that the software is doing what it is supposed to be doing. 他们确保软件正在执行应有的功能

Unit tests , on the other hand, aren't particularly useful for customers. 另一方面, 单元测试对客户而言并不是特别有用。 A customer is not concerned that the InitializeServerConnection is failing, but they are concerned that they're unable to send internal messages to their co-workers as a result. 一位顾客并不担心, InitializeServerConnection失败,但他们担心,他们无法内部消息发送到他们的同事作为一个结果。

So what good are unit tests for? 那么单元测试有什么用呢? They are a development tool, full stop. 它们是一个开发工具,是一站式服务。 A unit test verifies that a cog in the machine is working properly. 单元测试可验证机器中的齿轮是否正常工作。 And if it is not, it is very easy to see it failing . 如果不是这样, 很容易看到它失败

Arialdo Martini offers a great explanation: Arialdo Martini提供了一个很好的解释:

Oversimplifying, a software system can be seen as a network of cooperating modules. 过于简化,软件系统可以看作是协作模块的网络。 Since they cooperate, some of them depend on other. 由于他们合作,因此其中一些人彼此依赖。

[...] [...]

With integration and end-to-end tests you would be able to find all the broken features. 通过集成和端到端测试,您将能够找到所有损坏的功能。 系统测试

Yet, this is not of any help in guessing where the bug is. 但是,这对于猜测错误的位置没有任何帮助。 The same system, with the same bug, would result in these unit test failures: 具有相同错误的同一系统将导致以下单元测试失败:

单元测试

So, even though a unit test doesn't add any business value, it does add value in the form of reducing the amount of time spent manually testing, debugging, and sifting through code looking for the root cause of an issue. 因此,即使单元测试不会增加任何业务价值,它也可以通过减少查找问题根源的手动测试,调试和筛选代码所花费的时间来增加价值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我已经编写单元测试和功能测试时,从集成测试中获得什么价值 - What value would I get from integration tests when I already write unit tests and functional tests 您可以在不创建测试代码的情况下执行单元/集成测试 - Can you perform unit / integration tests without creating test codes? 当我已经有了集成测试时,我应该为 CRUD 操作编写单元测试吗? - Should I write Unit-Tests for CRUD operations when I have already Integration-Tests? Azure Devops - MSTest - 如果我的单元测试失败,我如何使构建失败,但在集成测试失败时继续(带有警告/通知) - Azure Devops - MSTest - How can I fail a build if my unit tests fail, but continue (with warning/notification) when integration test fail 单元测试和集成测试之间的界限在哪里(例如)? - Where is the line between unit and integration test (on example)? Junit:拆分集成测试和单元测试 - Junit: splitting integration test and Unit tests 单元测试是否会在集成测试之外为DAL提供程序的这个示例添加任何值? - Would a Unit Test add any value to this example of a DAL provider beyond an Integration Test? 将单元测试添加到现有项目? - Adding Unit Tests to an already existing project? 了解测试(BDD) - 我是否可以跳过单元测试重复某些集成测试中已涵盖的内容? - Understanding testing (BDD) — Can I skip Unit Test duplicating something that is already covered in certain Integration Test? 我应该使用纯单元测试还是集成测试来测试命令模式? - Should I test the command pattern with pure unit tests or integration tests?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM