此文转载自:http://coolshell.cn/articles/5531.html
——————————————正文开始——————————————
对于程序员来说有些事有非常危险的信号(red flag)。当我听到有人开始信仰Test-DrivenDevelopment是 One True Programming Methodology(唯一正确的编程方法论),这就是危险信号(red flag),我开始假设你是一个劣等、没有经验的程序员,或是某些敏捷咨询师。
测试只是一个工具来帮助你,而不是用来证明谁比谁更虔诚,或是我的屌比你的要大,等这种愚蠢的行为。测试是用来让程序员得到有帮助的、更快的反馈,从而找到正确的路径,如果你搞坏一些事,其还可以用来给后人一些警告。这根本就不是一个神秘的有魔力的方法其可以让你的代码变得更好……
整个Test-DrivenDevelopment的概念是麻痹和信奉,从而让其成为你的人生观。相反的:Developer-Driven Testing,它给你和你的同事一些有用的工具来解决问题,来支持你自己,而不是那种以工具或方法为中心的让你假设其应该是那样的测试。
是不是在有些时候我们需要在写代码前写测试?当然是,比如,“修改已有的功能”,这会一个适用的场景,还有那些短小的和已定义完善的事物,或是对已被测试过的代码做一些改善。
但, 是不是你就应该需要总是要去先写测试?省省吧,别逗了。
这是极度白痴的行为,尤其是在设计,调查和开发的初期。让你的测试来接管你的代码(而不是影响那个模块的代码)和接管你的设计 这是一个巨大的失败,就是因为你写的那些测试范围太大太不靠谱。(陈皓注:我在《TDD并不是看上去的那么美》一文中说过测试案例的测试范围的问题,敏捷社区除了对我进行人身攻击外从未对此做过正面回答。)
在写代码前写测试案例在一些场景下的确很不错。然后,Test Driven Development,被敏捷专家或是其它各种五花八门的像神给凡人宣扬一样,这就是欺骗大众。
行动在想法之下,于是测试必需先行(所有我已看到的,所有我正在看到的都表明这是TDD的中心思想—— 你写了测试,然后你再写代码并通过测试),于是测试成为了最有用的活动并可以帮助程序员。这是错的。
就算你在一开始要写一些测试案例,但只要你想让这些测试案例更有意义,那么,你要么得让这些测试案例的测试范围更小更底层更精确,要么你就得在整个软件快要写完的时候再去写测试,要不然你就得欺骗或是篡改测试案例。在为数不多的情形下,前者是正确的——测试围绕于bug,或是小的,定义地很好的功能碎片(陈皓注:我个人理解为单元测试是目前最有效的))
把测试变成整个活动的中心因为其对程序员有用?真牛逼。老实说,控制程序员的工作流程只可能得出一条无比正确的答案——荒谬可笑。
测试帮助程序员,是因为其可以帮程序员组织自动化测试,所以才帮了程序员,而不是cargo-cult(货物崇拜,参看《各种流行的编程方法》中的cargo-cult编程)——信仰一种工作流程并让所有的人或事来适应于他。
先写测试这种方法只会在“Developer Driven Testing”(程序员自己驱动的测试)下可行——关注于选取一个正确的方法让程序员更有生产力。生成一堆测试的规则并说这是唯一的真理是不正确的。
一些讨论和想法(在此贴发出数小时后)…
当我这篇博文发出几个小时后,其被转到了别的地方并引发了一些讨论。
在Hacker News上,有人说我提出了很多很不错的问题,并且那是真正的有理有据的观点。我在用用户名叫peteretep的回复了一些。
在Reddit上的争论更多更强。那里有很多的人觉得需要写自动化测试。并且这篇博文被大家演变成拥护测试和可实践的建议,我觉得我是误传达了我的想法,我觉得软件测试是非常重要的,而不是根据哪个方法论进行的教条主义!
分享到:
相关推荐
Test-Driven Development: A Practical Guide By David Astels
Test-Driven Development (TDD) is a methodology that helps you to write as little as code as possible to satisfy software requirements, and ensures that what you've written does what it's supposed to ...
Test-Driven Development with Python, 2nd Edition English | 2017 | ISBN-10: 1491958707 | 592 pages | PDF,MOBI,EPUB (conv) | 8.59 Mb By taking you through the development of a real web application from...
Test-driven development (TDD) is a development approach that relies on a test-first procedure that emphasises writing a test before writing the necessary code, and then refactoring the code to ...
Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and JavaScript by Harry J. W. Percival English | 2 Aug. 2017 | ISBN: 1491958707 | ASIN: B074HXXXLS | 604 Pages | AZW...
Test-Driven Development简称TDD,中文为测试驱动开发。是一种不同于传统软件开发流程的新型的开发方法。它要求在编写某个功能的代码之前先编写测试代码,然后只编写使测试通过的功能代码,通过测试来推动整个开发的...
Test-Driven Development by Example.rar
Presents an expert overview of TDD and agile programming techniques from the Java developer's perspective Brings together practical best practices for Java, TDD, and OO design Walks through setting ...
This book is about programming JavaScript for the real world, using the techniques and workflow suggested by Test-Driven Development. It is about gaining confidence in your code through test coverage,...
Test-driven development (TDD) is a development approach that relies on a test-first procedure that emphasises writing a test before writing the necessary code, and then refactoring the code to ...
Test-driven development (TDD) is a proven way to find software bugs early. Writing tests before your code improves the structure and maintainability of your app. Test-driven iOS Development with ...
Test-Driven Development with Python 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请...
Test-driven development replies to this contradiction with a paradox-test the program before you write it. A new idea? Not at all. Since the dawn of computing, programmers have been specifying the ...
Test-Driven Development with Python(2nd) 英文无水印pdf 第2版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有...
Test-Driven Development with Python 最新版 2014年6月9日出版 原版pdf,非扫描版
Agile Java Crafting Code with Test-Driven Development.chm
This book will teach the concepts of test driven development in Java so you can build clean, maintainable and robust code About This Book Explore the most popular TDD tools and frameworks and become...
Test-Driven Development with Python Obey the Testing Goat: Using Django, Selenium, and JavaScript.Python 经典图书, 清晰文字源生PDF,带目录标签。2017年第二版。