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

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/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/395822.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java ews_Java---使用EWS 写个ExchangeMailUtil

依赖包:commons-httpclient-3.1.jarcommons-codec-1.10.jarcommons-logging-1.2.jarjcifs-1.3.17.jar代码示例:创建MailBean类:import java.util.Date;public class MailBean {public BigDecimal getId() {return id;}public void setId(BigD…

Ilya Muromets(DP or 思维)

Ilya Muromets Gym - 100513F Силачом слыву недаром — семерых одним ударом!From the Russian cartoon on the German fairy tale.Ilya Muromets is a legendary bogatyr. Right now he is struggling against Zmej Gorynych, a drago…

C# 装箱和拆箱

C#的值类型可以分为在栈上分配内存的值类型和在托管堆上分配内存的引用类型。 1、那么值类型和引用类型能否相互转换呢? 答案是肯定的,C#通过装箱和拆箱来实现两者的相互转换。 (1)、装箱 ---把值类型强制转换成引用类型(object类型) (2)、拆箱 ---把引用类型强制转换成值…

第五章

学会了开发板测试环境的调试和烧写android系统。 学到的知识: 一、安装串口调试工具:minicom 第1步:检测当前系统是否支持USB转串口。 # lsmod | grep usbserial 第2步:安装minicom # qpt-get install minicom 第3步:配置minicom # minicom -…

Angular的后院:组件依赖关系的解决

by Dor Moshe通过Dor Moshe Angular的后院:解决 组件依赖关系 (Angular’s Backyard: The Resolving of Components Dependencies) This article originally appeared on dormoshe.io这篇文章 最初出现在dormoshe.io Many of us use the Hierarchical Dependenc…

node中的Stream-Readable和Writeable解读

在node中,只要涉及到文件IO的场景一般都会涉及到一个类-Stream。Stream是对IO设备的抽象表示,其在JAVA中也有涉及,主要体现在四个类-InputStream、Reader、OutputStream、Writer,其中InputStream和OutputSt…

新Rider预览版发布,对F#的支持是亮点

JetBrains一直在改进自己的跨平台.NET IDE产品Rider,努力使其成为Visual Studio家族产品可承担职能的重要替代者。于今年四月发布的Rider预览版(EAP 21)提供了一些新特性,其中的亮点在于对函数式编程语言F#的支持。\\鉴于这是Ride…

java代码整合_java合并多个文件的实例代码

在实际项目中,在处理较大的文件时,常常将文件拆分为多个子文件进行处理,最后再合并这些子文件。下面就为各位介绍下Java中合并多个文件的方法。Java中合并子文件最容易想到的就是利用BufferedStream进行读写。具体的实现方式如下,…

正则表达式的一些规则

1.限定修饰符只对其紧前的元字符有效 String rex8 "\\d\\D"; 上式中,只对\\D有效,即有至少有1个(1个或多个)非数字,\\d仍然只许有一个数字。 2.[1,2,3]和[123]是一样的转载于:https://www.cnblogs.com/Sabr…

2016版单词的减法_在2016年最大的电影中,女性只说了27%的单词。

2016版单词的减法by Amber Thomas通过琥珀托马斯 在2016年最大的电影中,女性只说了27%的单词。 (Women only said 27% of the words in 2016’s biggest movies.) Movie trailers in 2016 promised viewers so many strong female characters. Jyn Erso…

软件工程博客---团队项目---个人设计2(算法)

针对分析我们团队项目的需求,我们选定Dijkstra算法。 算法的基本思想: Dijkstra算法是由E.W.Dijkstra于1959年提出,又叫迪杰斯特拉算法,它应用了贪心算法模式,是目前公认的最好的求解最短路径的方法。算法解决的是有向…

UWP 杂记

UWP用选取文件对话框 http://blog.csdn.net/u011033906/article/details/65448394 文件选取器、获取文件属性、写入和读取、保存读取和删除应用数据 https://yq.aliyun.com/articles/839 UWP判断文件是否存在 http://blog.csdn.net/lindexi_gd/article/details/51387901…

微信上传素材 java_微信素材上传(JAVA)

public String uploadMaterial(String url,InputStream sbs,String filelength,String filename, String type) throws Exception {try {DataInputStream innew DataInputStream(sbs);url url.replace("TYPE", type);URL urlObj new URL(url);// 创建Http连接HttpU…

SQL Server读写分离之发布订阅

一、发布 上面有多种发布方式,这里我选择事物发布,具体区别请自行百度。 点击下一步、然后继续选择需要发布的对象。 如果需要筛选发布的数据点击添加。 根据自己的计划选择发布的时间。 点击安全设置,设置代理信息。 最后单击完成系统会自动…

码农和程序员的几个重要区别!

如果一个企业老板大声嚷嚷说,“我要招个程序员”,那么十之八九指的是“码农”——一种纯粹为了钱而写代码的技术人员。这其实是一种非常狭隘和错误的做法,原因么,且听我一一道来。1、码农写代码,程序员写系统从本质上讲…

sql server2008禁用远程连接

1.打开SQL Server 配置管理器,双击左边 SQL Server 网络配置,点击TCP/IP协议,在协议一栏中,找到 全部侦听,修改为否,然后点击IP地址,将IP地址为127.0.0.1(IPV4)或::1(IPV6)的已启用修改为是,其它的IP地址的已启用修改为否 注意:如…

snapchat注册不到_从Snapchat获得开发人员职位中学到的经验教训

snapchat注册不到Here are three links worth your time:这是三个值得您花费时间的链接: I just got a developer job at Snapchat. Here’s what I learned and how it can help you with your job search (15 minute read) 我刚刚在Snapchat获得开发人员职位。 这…

java bitmap jar_Java面试中常用的BitMap代码

引言阿里内推面试的时候被考了一道编程题:10亿个范围为1~2048的整数,将其去重并计算数字数目。我看到这个题目就想起来了《编程珠玑》第一章讲的叫做BitMap的数据结构,但是我并没有在java上实现过,这就比较尴尬了,再加…

移动端工程架构与后端工程架构的思想摩擦之旅(1)

此文已由作者黎星授权网易云社区发布。欢迎访问网易云社区,了解更多网易技术产品运营经验记资源投放后端工程的架构调整与优化 架构思考一直以来对软件工程架构有着极大的兴趣,无论是之前负责的移动端Android工程,亦或是现在转到后端开发后维…

View野指针问题分析报告

【问题描述】 音乐组同事反馈了一个必现Native Crash问题&#xff0c;tombstone如下&#xff1a; pid: 5028, tid: 5028, name: com.miui.player >>> com.miui.player <<< signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 79801f28r0 7ac59c98 r1 …