单元测试与验收测试 [英] Unit Tests vs. Acceptance Tests

查看:48
本文介绍了单元测试与验收测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你赞成其中之一吗?还是两者兼而有之?

Are you for one or the other? Or both?

我的理解是单元测试:

  • 从开发者的角度验证系统
  • 帮助开发者实践 TDD
  • 保持代码模块化
  • 协助检测低粒度级别的错误

验收测试:

  • 从业务和 QC/QA 的角度验证系统
  • 往往是高级别的,因为它们通常是由不熟悉代码内部工作原理的人编写的

我觉得两者都是必要的.但是,为了尽量减少冗余工作,尝试将单元测试合并到验收测试中是否是个好主意?换句话说,让后者调用前者.往相反的方向走有意义吗?

I feel both are necessary. However, for minimization of redundant work, is it a good idea to try to incorporate unit tests into acceptance tests? In other words, have the latter call the former. Does going in the opposite direction make any sense?

您对单元测试与验收测试的总体看法是什么,以及如何管理它们之间的关系?

What are your thoughts in general on unit tests vs. acceptance tests, and how to manage them in relation to each other?

推荐答案

验收和集成测试告诉你你的代码是否工作和完整;单元测试会告诉你它在哪里失败.

Acceptance and integration tests tell you whether your code is working and complete; unit tests tell you where it's failing.

如果您在验收和集成测试方面做得很好,并且它们通过了,那么您的代码正在实现它应该实现的所有功能,并且可以正常工作.很高兴知道(知道它不是也很棒).但如果它不起作用,验收测试将无法让您深入了解出了什么问题.因为它测试了许多功能单元,所以它可以是故障的鸟瞰图.这就是单元测试闪耀的地方.好的单元测试会准确地告诉您代码的哪一部分出了什么问题.与验收测试相比,很难知道您是否编写了足够多的单元测试,但是当您的验收测试失败而没有相应的单元测试失败时 - 是时候编写该单元测试了.

If you've done a good job with acceptance and integration tests, and they're passing, your code is implementing all the functionality it's supposed to, and it's working. That's great to know (it's also great to know that it isn't). But if it isn't working, an acceptance test won't give you much insight into what has gone wrong; since it tests many units of functionality, it can be kind of a bird's-eye view of failure. This is where unit tests shine. Good unit tests tell you exactly what went wrong, with exactly what part of your code. It's harder to know whether you've written enough unit tests than acceptance tests, but when you have a failing acceptance test without a corresponding failing unit test - it's time to write that unit test.

这都是从测试的角度来看的.而且,当然,TDD 与测试无关(而 ATDD 也不是).关于推动您的设计,验收测试为您提供了一个广泛的路线图(这是您想去的地方"),而单元测试将您带到下一个路口(左转").它们在这方面都很有价值,而且它们的价值也是互补的.

That is all from the testing perspective. And, of course, TDD isn't (and ATDD isn't) about testing. With respect to driving your design, acceptance tests give you a broad roadmap ("here's where you want to go") while unit tests take you to the next intersection ("turn left"). They're both valuable in this regard and, again, their value complement one another.

不要混淆它们;不要把他们混为一谈.特别是,单元测试不应该依赖于任何其他东西,并且通过让验收测试依赖于它们来限制单元测试是错误的.当然它们可以共享一些框架代码,但它们应该是独立的.

Don't confuse them; don't miscegenate them. Unit tests, in particular, shouldn't depend on anything else, and it would be a mistake to constrain your unit tests by making acceptance test dependent on them. Of course they can share some framework code, but they should be independent.

这篇关于单元测试与验收测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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