单元测试启蒙的五个阶段

免责声明:这篇文章旨在娱乐,并且也许(也许)使您反思了与软件单元测试的关系。

不定期编写单元测试的开发人员,不想开始writingunittests.Probablyduetoinertia,thenaturaltendencytoresistchange.Itseemstoocumbersome.Oncethosesamedevelopers开始writingtests,however,theyquicklyfind,totheirsurprise,thattheyareinfact,enjoyingit.谁曾想到Thereisakindofgamificationqualitytounittesting.Seeingthatgreenbarofpassedteststickuptoaperfectscoreof100%isnotunlikethenever-endinghuntforlootorexperiencepointsofthegrindergamesthatattractsomanypeople.Itis,forsomereason,appealingtous,tocollectthosepoints.Developersgetpulledin—theygethooked.

很快,他们发现自己花费更多的时间编写测试。 他们想要-不,他们需要-代码覆盖率稳定在100%。 因此,他们整天都在堆栈溢出为了弄清楚如何欺骗他们的测试框架,使他们相信实用程序类的私有构造函数(绝不会以任何形式,形状或形式在生产中被调用)实际上已经被测试覆盖了。 他们测试了所有代码,甚至遍及整个代码库的各种琐碎方法–需要去测试一切,每个分支都必须覆盖。 At this point, they are just procrastinating through writing a plenitude of tests. They feel that it’s much easier to write tests than to get started on that next feature that their users 需要 (for which, by the way, the requirements are way too vague anyway). 只是,一个(更多)代码行涵盖了…

我们(开发人员)都在探索启蒙的过程中,这就是它的发展方向。

Unit testing ignorant

在一开始,您很可能根本不会为编写测试而烦恼。 当然,您有点理解它们的意思,但是,这不适合您。 根本不值得麻烦。 您需要处理生产代码。 真正的代码很重要,对那就是你真被评估,对那么,为什么要花时间编写无关的单元测试呢您的测试和质量检查小组会发现所有流浪错误,之后,对此时,您是单元测试无知。 有些人在整个职业生涯中都会这样。 您内在的任何事物都无法推动您前进。 如果周围的每个人都对单元测试一无所知,那么这就是他们将无限期地停留的地方。 要前进,需要外部的东西。 需要采取一些措施来破坏现状。

Unit testing hesitant

在某个时候,您被迫开始编写单元测试。 可能是经理,技术主管,同事,或者是您对自我价值不断下降的印象,这使您入门。 您开始编写测试主要是为了编写测试。 如果您遇到一分钟或更短时间内无法弄清的代码怎么样要测试,您会悄悄地忽略它。 “到底是什么嘲笑还有一个间谍,无论如何,你问自己。 您测试您的吸气剂和装夹器,就是这样。 您现在有资格获得单元测试犹豫。

Unit testing enthusiast

接下来发生的事情对于您和您周围的每个人来说都是不可想象的且奇妙的。 突然,在编写了几百行测试代码之后,这个过程(上面提到的天堂)实际上开始变得令人愉快。 您意识到这还不是很糟糕。 当您看到绿色条缓慢爬升到100%时(或者您的测试服的颜色被更好地描述为:翠翡翠果然听起来更珍贵,不是吗而最宝贵的就是您的测试服,对。 所有测试均通过。 当然,每隔一段时间,您可能需要团队中的专家向您描述如何捕获传递给模拟的参数。 但是,您绝对是在正确的轨道上。 你告诉自己。 当您开始说服他人编写测试时,您现在已经转变为一名单元测试爱好者, 对你有益!

Unit testing fanatic

不知不觉中您 are that guru。 You know all there is to know about mocks and fakes, TDD and BDD。 Your non-programmer-friends thinks 您 have become interested in pickling vegetables, like all the other hipsters, because of 您r constant ramblings about Gherkin。 The code 您 write is absolutely, one hundred percent, testable。 Dependency injection is second nature to 您—and non-negotiable。 Your code can effortlessly be injected, stubbed, faked, spied, mocked or what have 您。 Not a flaky test in sight。 如果您无法测试,然后没有人 can。 The tests themselves have become more important to 您 than anything else。 More important to 您 than 您r production code and, with that, more important than 您r users and the business itself。 Hours are spent on online forums to find out how to trick 您r testing framework into giving 您 full coverage。 You book 您r managers for a sit-down, to tell them about the cost-effectiveness of unit tests, and how “it’s of utmost importance that we never, ever, for no reason, what-so-ever, allow a single line of code to be committed without it being adequately covered by tests “。 You are, at this point, effectively procrastinating by writing tests。 Also, what’s worse, 您 have turned into a 测试狂热者。

Unit testing pragmatist

有人达到了单元测试的顶峰,这是我们旅程的最后阶段。 提醒您,很少有人会来到这里,因为一路走来很容易卡住。 就像在机管局,迈向恢复的第一步就是要真正地向自己承认自己有问题。 您过分的测试是你的问题。 在极端的情况下,同事们厌倦了测试狂热者的热情,并组织了一次干预-哦,多么尴尬! 只有意识到了问题,您才能达到测试的禅定标准,并成为单元测试实用主义者. Testing pragmatism, testing enlightenment, reaching unit testing insight, nirvana, what have 您. At this point, 你的 testing journey has come full circle, returning to where 您 started; at the notion that delivering features and production code is 你的 main objective. Unit testing is a mere tool to get features out the door more quickly and with fewer bugs. It is for 您 to feel reassured that 你的 code does what 您 believe it should do, it is not for proving anything to anyone else—and certainly not top-out some, seemingly arbitrary, metric or KPI. Your tests are there to future-proof and to document 你的 solutions. 您可以测试复杂的,非平凡的,对业务至关重要的代码,而使获取器和设置器不受影响。 您可以使用第三方代码,边缘案例,最近可能更改的代码或将来可能更改的代码来测试集成和接口。

您那混蛋的私人构造函数不再让您彻夜难眠。 作为程序员,您过着更加平衡,快乐,幸运和充实的生活,这使您的同事感到高兴,并使客户和客户感到满意。

我也在旅途中,发现自己介于狂热者和狂热者之间。 我正在努力改善。 哦,男孩,我正在努力改进。 从许多方面来看,这与禅宗僧侣对启蒙运动的追求相似:尝试越努力,到达那里的可能性就越小。

你走了多远/p>

from: https://dev.to//saidaspen/the-five-stages-to-unit-testing-enlightenment-3cli

相关资源:翠雨方工作备忘录工具v2.31中文绿色版-其它代码类资源-CSDN文库

来源:cunxiedian8614

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年3月19日
下一篇 2020年3月20日

相关推荐