你应该使用测试驱动开发的7个缘由

本文翻译自dev.iophp

If you aren’t familiar with it, test-driven development (TDD) is a software development practice where you write tests before you write application code.编程

测试驱动开发(TDD)是一种软件开发实践,是在开始书写应用代码以前先写测试代码。app

TDD is something most computer science students are taught, but are never actually required to use. And you can get away without doing it for most of your coursework. (I have some thoughts on that here.)框架

大多数计算机科学的学生都学过TDD,可是从没实际的被要求使用过。并且在你的大多数课堂做业中能够逃避使用它。(对着它这里我有一些想法)ide

At any rate:函数

至少:学习

  1. Good tests make good documentation – both for you and anyone who might come onto your project later. Test frameworks like Jasmine and Jasmine read like plain English. Name your tests in a way that describes the tested function’s behavior in a particular circumstance.

好的测试产生好的文档-你或者其余人均可能会再去浏览你的项目。测试框架好比Jasmine和Jasmine读起来就像是日常的英语。以一种描述特定环境下的测试函数的行为的方式来命名测试。测试

  1. You’ll code faster. Even if writing a correct function implementation is difficult, pre-written tests will give you a clear target to hit.

你将会更快的编程。即便写一个正确的函数的实现都是困难的,提早编写测试将给你一个清晰的目标。ui

  1. You’ll code correctly faster. Keep your test runner open to get continuous feedback on your work. This will get you to a correct implementation faster than coding an entire module at once and then testing it.

在工做中让你的测试跑起来以获取不断的反馈,书写代码会更快和正确。这将使您更快地实现一个正确的实现,而不单单是对整个模块进行所有编码,而后再去测试它。编码

  1. You won’t forget to write the tests. Code without tests should make you uneasy, period. A comprehensive, passing test suite is reassurance to you and other developers that your code (probably) won’t break.

你不会忘记写测试,没有测试的代码会让你不安。一个全面的、经过的测试套件可让您和其余开发人员放心,您的代码(可能)不会中断。

  1. It provides a solid starting point for later work. Similar to #1. Also, if you pick a project back up after a few months, you’ll forget how most of the code works. Tests can be a reminder, and a tested code base can be a fallback if you suddenly break things.

它为之后的工做提供了坚实的起点。相似于第一条。此外,若是你在几个月后从新回到某一个项目,你会忘记大部分代码是如何工做的。测试能够提醒你,若是你忽然弄乱来一些东西,测试代码库能够是一个参考。

  1. It pushes you to write cleaner code. Long, complicated functions are hard to test. Simple tests and clear descriptions will naturally lead to shorter, more readable application code.

它迫使你去写更加简洁的代码。长且复杂的函数是很难测试的。简单的测试和清晰的表达天然的产生更短和更具可读性的应用代码。

  1. You’ll write more meaningful tests. With code already written, it’s easy to write tests that just pass instead of tests that confirm useful functionality. Imagine if your math professor only tested you on things you already knew – that wouldn’t be very useful!

你将书写更有意义的特产。若是提早写好来代码,就很容易去写为了经过而写的测试, 而不是为了验证有用的功能。想象一下若是你的数学老师只是测试你已经知道的东西,那将没有意义!

你有其余的理由吗?在下面的评论区里面写上你的想法。

欢迎做客咱们的php&Laravel学习群:109256050

相关文章
相关标签/搜索