为什么功能测试还不够?单元测试提供什么? [英] Why are functional tests not enough? What do unit tests offer?

查看:94
本文介绍了为什么功能测试还不够?单元测试提供什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚与我的首席开发人员进行了交谈,后者不同意单元测试是必要的或重要的.他认为,具有足够高代码覆盖率的功能测试就足够了,因为任何内部重构(接口更改等)都不会导致需要重写或再次检查这些测试.

I just had a conversation with my lead developer who disagreed that unit tests are all that necessary or important. In his view, functional tests with a high enough code coverage should be enough since any inner refactorings (interface changes, etc.) will not lead to the tests being needed to be rewritten or looked over again.

我尝试解释一下,但距离还很远,并认为你们可以做得更好. ;-)所以...

I tried explaining but didn't get very far, and thought you guys could do better. ;-) So...

功能测试不提供的单元测试代码有哪些很好的理由?如果您只有功能测试,那会有什么危险?

What are some good reasons to unit test code that functional tests don't offer? What dangers are there if all you have are functional tests?

编辑#1 :感谢您提供的所有出色答案.我想补充一点,通过功能测试,我不仅意味着要对整个产品进行测试,而且还要对产品中的模块进行测试,只是在底层测试(如果有必要的话)上不进行底层测试,等等.还请注意,我们的功能测试是自动的,并且可以连续运行,但是它们比单元测试花费的时间更长(这是单元测试的一大优势).

Edit #1 Thanks for all the great answers. I wanted to add that by functional tests I don't mean only tests on the entire product, but rather also tests on modules within the product, just not on the low level of a unit test with mocking if necessary, etc. Note also that our functional tests are automatic, and are continuously running, but they just take longer than unit tests (which is one of the big advantages of unit tests).

我喜欢砖砌房屋的例子.我想我的主要开发人员说的是测试房屋的墙壁就足够了,您不需要测试单个的砖块...:-)

I like the brick vs. house example. I guess what my lead developer is saying is testing the walls of the house is enough, you don't need to test the individual bricks... :-)

推荐答案

离我远去

  • 单元测试无需费力即可重复.编写一次,运行数千次,无需人工,并且比功能测试获得更快的反馈
  • 单元测试将测试小型单元,因此请立即指向发生错误的正确扇区".功能测试指出了错误,但是它们可能是由大量模块引起的,即使在合作中也是如此.
  • 我几乎不将接口更改称为内部重构".接口更改往往会破坏很多代码,并且(在我看来)强制执行新的测试循环,而不是没有.

这篇关于为什么功能测试还不够?单元测试提供什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆