[英]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.