This post was originally published on Medium

这篇文章最初发表于Medium

Writing tests represents one of those few stages of software development that is usually overlooked, even though it may be one of the most important one. Developers mention it and usually are either uncomfortable and prefer not to write tests for their code, or have many excuses for not writing them at all.

编写测试代表了通常被忽略的那几个软件开发阶段之一,尽管它可能是最重要的阶段之一。 开发人员会提到它,通常会感到不舒服,他们不愿意为他们的代码编写测试,或者有很多借口根本不编写代码。

Well, tests are important:

好吧,测试很重要:

  • A software bug in a Therac-25 radiation therapy machine caused the death of five patients after receiving a massive dose of X-rays.

    Therac-25放射治疗机中的软件错误在接受大量X射线照射后导致五名患者死亡。

  • Knight Capital lost half a billion dollars in half an hour when a software bug allowed computers to sell and buy millions of shares with no human oversight.

    骑士资本(Knight Capital)在半小时内损失了10亿美元,当时一个软件漏洞允许计算机在无人监督的情况下买卖计算机。

These and many other stories tell how seemingly unimportant bugs can actually cause so many tragic disasters.

这些故事以及其他许多故事都说明,看似不重要的错误实际上会导致如此多的悲剧性灾难。

We know how critical software is becoming to every area of our lives. We know that the security, stability and correctness of this software has a crucial importance in our lives. So the question is: why do developers still avoid writing tests?

我们知道关键软件在我们生活的各个领域都变得越来越重要。 我们知道,该软件的安全性,稳定性和正确性对我们的生活至关重要。 所以问题是:为什么开发人员仍然避免编写测试?

借口1:“笔试只会花太多时间。” (Excuse #1: “Writing tests just takes too much time.”)

It’s easy to perceive writing tests as taking too much time, as opposed to jumping directly into the implementation part.

很容易将编写测试视为花费大量时间,而不是直接跳到实现部分。

This may be true in the short term, but if we take into consideration the time you may potentially need to fix all the bugs you could avoided by writing tests, then writing tests can actually save time — and even money — along the way.

在短期内这可能是正确的,但是如果考虑到时间,您可能需要修复通过编写测试可以避免的所有错误,那么编写测试实际上可以节省时间,甚至节省金钱。

Tests do not eliminate bugs completely (nothing can do that), but they can dramatically reduce them. They can even make you feel more confident that you’re not breaking any existing functionality when you add new features and refactor old ones.

测试不能完全消除错误(没有办法做到),但是可以大大减少错误。 它们甚至可以使您更有信心,在添加新功能并重构旧功能时不会破坏任何现有功能。

Tests also help you save time and protect your existing implementations from inexperienced programmers who recently joined your team. If these newcomers introduce bugs, your tests will fail. And when your tests fail, you become aware that something went wrong.

测试还可以帮助您节省时间,并保护您的现有实现免受最近没有经验的程序员(加入您的团队)的侵害。 如果这些新手引入了错误,则您的测试将失败。 当测试失败时,您会意识到出了点问题。

Project managers who lack a programming background — and thus may not understand the programming complexities that may arise all of a sudden — tend to have high expectations of the developers on their teams. They want to things done quickly, and fast production-ready code. They may consider it unreasonable to postpone a strict deadline.

缺乏编程背景的项目经理(因此可能无法理解突然出现的编程复杂性)往往对团队中的开发人员抱有很高的期望。 他们希望快速完成事情,并快速准备生产代码。 他们可能认为推迟严格的截止日期是不合理的。

These situations may put you into tough situations — where you have to choose between following best practices or getting things done quick-and-dirty.

这些情况可能会使您陷入困境–在这种情况下,您必须选择遵循最佳实践或快速完成工作。

You should try and find a few professional principles you can stick to no matter what. You should try your best to convince your manager of the importance of best practices, and how they pay off in the long run. And if your manager can’t be convinced, then you may consider changing jobs.

您应该尝试找到一些无论如何都可以坚持的专业原则。 您应该尽力使您的经理相信最佳做法的重要性,以及从长远来看它们如何产生收益。 而且,如果无法说服您的经理,那么您可以考虑换工作。

借口2:害怕编写测试 (Excuse #2: the fear of writing tests)

It’s no surprise that developers spend most of their working hours either reading code, writing code, or discussing new problems to solve with code. As a result, they have a very strong emotional attachment to it, and prefer to treat it as their precious property.

开发人员将大部分工作时间花费在阅读代码,编写代码或讨论要用代码解决的新问题上也就不足为奇了。 结果,他们对它有着强烈的情感依恋,并喜欢将其视为自己的宝贵财产。

Many are confident that they’re already experienced enough, and that they are capable of covering every possible scenario without much effort.

许多人相信自己已经有足够的经验,并且能够轻松应对各种可能的情况。

On the inside, they may harbor a sense of insecurity. And subjecting their code to tests may cause that insecurity to flare up.

在内部,他们可能怀有不安全感。 对他们的代码进行测试可能会导致这种不安全感加剧。

Maybe they pushed their code changes to the master branch faster than they should have, because they want to look like a productive employee to their manager. And now they’re afraid that writing tests might reveal bugs in their code. They’re afraid of being exposed as average programmers who cannot write bug-free code.

也许他们将代码更改推送到master分支的速度比他们应有的速度快,因为他们希望在经理中看起来像是富有成效的员工。 现在,他们担心编写测试可能会发现其代码中的错误。 他们害怕被无法编写无错误代码的普通程序员所接受。

Well, we should all do ourself a favor and never let our own sense of ego delude us into not writing tests. As uncomfortable as it may feel, we should take responsibility for our own work. This is one of the best ways to avoid bugs — bugs which can often have tragic consequences.

好吧,我们都应该帮自己一个忙,不要让我们自己的自我意识欺骗我们不编写测试。 尽管感觉不舒服,我们应该为自己的工作负责。 这是避免bug的最佳方法之一,而bug往往会带来悲剧性的后果。

Tests allow you to make big changes in your code quickly, since you can be confident that everything is working correctly. When you’re used to writing tests for your code, you will then usually be able to finish off your work a lot faster, as you will have instant visual feedback when something is failing as you will see a red light. As a result, you will also write better code, feel less stress, and eventually get promoted, as you’re ultimately bringing in more value with the work that you are doing.

测试使您可以快速地对代码进行重大更改,因为您可以确信一切正常。 当您习惯于为代码编写测试时,通常可以更快地完成工作,因为当出现故障时您会立即获得视觉反馈,因为您会看到红灯。 结果,您还将编写更好的代码,减轻压力,并最终获得晋升,因为您最终将通过所做的工作带来更多价值。

抽出时间进行测试 (Make time for testing)

Tests will never be able to catch 100% of bugs, but they will contribute to the security, stability and correctness of your code. Make time for them.

测试将永远无法捕获100%的错误,但是它们将有助于代码的安全性,稳定性和正确性。 为他们腾出时间。

This post was originally published on Medium

这篇文章最初发表于Medium

翻译自: https://www.freecodecamp.org/news/2-most-frequent-reasons-why-developers-avoid-writing-tests-e13fc74ee2ab/

开发人员避免编写测试的2个最常见原因相关推荐

  1. 初级测试开发面试题_初级开发人员在编写单元测试时常犯的错误

    初级测试开发面试题 自从我编写第一个单元测试以来已经有10年了. 从那时起,我不记得我已经编写了成千上万的单元测试. 老实说,我在源代码和测试代码之间没有任何区别. 对我来说是同一回事. 测试代码是源 ...

  2. 初级开发人员在编写单元测试时常犯的错误

    自从我编写第一个单元测试以来已经有10年了. 从那时起,我不记得我已经编写了成千上万的单元测试. 老实说,我在源代码和测试代码之间没有任何区别. 对我来说是同一回事. 测试代码是源代码的一部分. 在过 ...

  3. foobar_Foobar挑战:Google对开发人员的隐藏测试

    foobar by Daniel Simmons 丹尼尔·西蒙斯(Daniel Simmons) Foobar挑战:Google对开发人员的隐藏测试 (The Foobar challenge: Go ...

  4. 从开发转到测试,做到让开发人员佩服的测试工程师之后···

    很多从事程序开发的人会在有一定开发经验后会转到测试岗位,其实测试岗位并不轻松,因为测试的结果直接会影响到软件的性能,进而影响到用户的体验.那么,从事开发的朋友如何转测试呢,笔者有下面几点建议. 1.首 ...

  5. 汉堡菜单_开发人员在编写汉堡菜单时犯的错误

    汉堡菜单 by Jared Tong 汤杰(Jared Tong) 开发人员在编写汉堡菜单时犯的错误 (The mistake developers make when coding a hambur ...

  6. 开发人员在编写 HTML 和 CSS 时最常犯的六大错误

    生活中犯错误是正常的,没有人不会犯错误,更何况是开发人员呢?今天我们就来卡看看开发人员在编写 HTML 和 CSS 时最常犯的六大错误有哪些. 作者 | Stas Melnikov 译者 | 弯月,责 ...

  7. 欢乐颂之鸿蒙系统,华为启动鸿蒙OS开发人员公开Beta测试的第二阶段

    5月10日消息,知名财经媒体报道称:上个月,华为针对更多设备(包括华为Mate 40系列,Mate X2和其他华为设备)开放了HarmonyOS 2.0开发者开放测试活动.随后,华为已开始针对上述设备 ...

  8. 如果您是开发人员,则应该开始写博客-这就是原因。

    by Isabel Nyo 通过伊莎贝尔·尼奥 一路走来的博客之旅和技能 (My blogging journey and skills I've acquired along the way) Th ...

  9. 我为何从开发人员转做测试,3年软件测试工程师,带你聊聊这其中的秘辛

    从事测试工作已3年有余了,今天想聊一下自己刚入门时和现在的对比,虽然现在也没什么成就,只能说笑谈一下自己的测试生涯,各位看官就当是茶余饭后的吐槽吧,另外也想写一写自己的职场感想,希望对刚开始工作的小伙 ...

最新文章

  1. 关于类的非静态函数指针成员变量
  2. Spring boot 将配置文件属性注入到一个bean中
  3. 在当今移动互联网时代_谁在提供当今最好的电子邮件体验?
  4. C++入门经典-例8.1-类的继承
  5. Java——网络编程(实现基于命令行的多人聊天室)
  6. python学生管理系统2.0-python3.6+django2.0开发一套学员管理系统
  7. Kubernetes 为 Namespace 配置CPU和内存配额
  8. 披星戴月地辛苦割胶或成历史,海南胶园迎来这一“神器”!
  9. 山寨十年,东鹏特饮终于打败红牛!但却很尴尬
  10. jboss mysql amp amp_怎么在JBoss中配置MySQL数据库连接池让Mysql支持中文
  11. python爬虫可以找种子吗_python3爬取torrent种子链接实例
  12. CryptoJS加密
  13. 数学知识:扩展欧几里得算法
  14. JAVA 二叉树面试题
  15. 微信支付解决多商户平台收款
  16. 品牌笔记本预装windows的OEM分区解决方案(联想)
  17. 从屏下指纹到体感手机,vivo能否走出自己的创新之路?
  18. 为VMware vSphere创建Ubuntu 18.04 Terraform模板
  19. Self-supervised
  20. 【TensorFlow】InternalError:Dst tensor is not initialized

热门文章

  1. 解析底层原理!Android开发者面试如何系统复习?帮你突破瓶颈
  2. 系统学Android从零开始,搞懂这些直接来阿里入职
  3. 浅谈“==”、equals和hashcode,以及map的遍历方法(可用作上一篇k-means博文参考)
  4. padding影响整个div的实际宽度
  5. JVM源码---教你傻瓜式编译openjdk7(JAVA虚拟机爱好者必看)
  6. C# 课堂总结2-数据类型及转换方式
  7. placeholder=请输入用户名(六位数字加英文字母)
  8. SQLServer 优化SQL语句 in 和not in的替代方案
  9. [个人推荐]函数式编程另类指南[zz]
  10. neroLinux3.x的序列号