開發人員避免編寫測試的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.pswp.cn/news/395822.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/395822.shtml
英文地址,請注明出處:http://en.pswp.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 …