多少单元测试是一件好事? [英] How much unit testing is a good thing?

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

问题描述

(似乎没有相关问题"可以解决这个问题,所以就这样吧.)

(No "related questions" seem to nail this, so here goes.)

我致力于生产代码.有时,为用户看不到的任何事情争论是很难做到的.如果销售人员看不到它,这对他们来说是一种外部成本,除非有充分的理由不这样做,否则他们会反对它.

I work on production code. Arguing for anything that isn't visible to the user is hard to do, sometimes. If sales can't see it, it's an external cost to them, and they'll argue against it unless there's a great reason not to.

多少单元测试是一件好事?如果你测试每一个类,每一个方法,你当前的版本将需要更长的时间,可能更长.如果您不进行任何测试,那么将来的维护将花费您更长的时间,甚至可能更长,因为错误修复和新功能会导致您无法预见的问题,并且单元测试会发现这些问题.

How much unit testing is a good thing? If you test every class, every method, your current release will take longer, possibly much longer. If you test nothing, maintenance in the future will take you longer, possibly much longer as bugfixes and new functionality cause problems you didn't foresee, and that the unit tests would have caught.

您如何找到健康、合理的平衡?

How do you find a healthy, justifiable balance?

回答一些理性的人提出的问题......

to answer a few questions that people reasonable have raised...

  1. 销售人员并没有运行该流程,但他们肯定有意见,并且应该在任何组中的意见都是有限的.他们是支付账单的人.如果他们完全掌控一切,那显然是不合理的.

  1. Sales isn't running the process, but they certainly have input, and should have limited input in any group. They're the ones who pay the bills. If they're completely steering everything, that would be unreasonable, obviously.

我确定没有最佳答案,但我很好奇其他人认为什么是合理的.我期待两个极端(一切!什么都没有!),中间还有很多.

I'm certain there's no best answer, but I'm curious as to what other people think is reasonable. I'm expecting both extremes (everything! nothing!), and a lot in the middle.

没有人可以选择他们的经理,如果一个糟糕的单元测试政策是一个决定留在公司/项目的人的成败决定......你有很多em> 比我们大多数人有更多的职业选择,朋友.:-)

No one gets to choose their manager, and if a bad policy on unit testing is a make-or-break decision in someone staying with a company/project... you have a lot more career options than most of us, friend. :-)

第二次合理"是其中的一个重要词.如果我想为单元测试预算/允许时间,并且不想偷偷溜进去,我需要证明原因.对我来说,现在最重要的答案是测试以前坏掉的东西",因为我总能证明被动策略是合理的.

Second "Justifiable" is an important word in there. If I want to have time budgeted/allowed for unit testing, and don't want to have to sneak it in, I'm going to need to justify the why. The top answer right now, for me, is "test things that have broken before", because I can always justify reactive policies.

关于如何证明积极主动的任何想法?

推荐答案

关于最小化单元测试的两个建议,将提供最大的物有所值":

Two suggestions for minimal unit testing that will provide the most "bang for the buck":

首先分析您的应用程序以查找最常用的部分 - 确保这些部分经过单元测试.继续向外移动到不常用的代码.

Start by profiling your application to find the most commonly used parts - make sure those are unit tested. Keep moving outward to the less commonly used code.

当一个错误被修复后,编写一个可以检测到它的单元测试.

When a bug is fixed, write a unit test that would have detected it.

这篇关于多少单元测试是一件好事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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