本文翻译自 dev.io
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 )是一种软件开发实践,是在开始书写应用代码之前先写测试代码。
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,但是从没实际的被要求使用过。而且在你的大多数课堂作业中可以逃避使用它。(对着它这里我有一些想法)
At any rate:
至少:
- 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 读起来就像是平常的英语。以一种描述特定环境下的测试函数的行为的方式来命名测试。
- You ’ ll code faster. Even if writing a correct function implementation is difficult, pre-written tests will give you a clear target to hit.
你将会更快的编程。即使写一个正确的函数的实现都是困难的,提前编写测试将给你一个清晰的目标。
- 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.
在工作中让你的测试跑起来以获取不断的反馈,书写代码会更快和正确。这将使您更快地实现一个正确的实现,而不仅仅是对整个模块进行全部编码,然后再去测试它。
- 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.
你不会忘记写测试,没有测试的代码会让你不安。一个全面的、通过的测试套件可以让您和其他开发人员放心,您的代码(可能)不会中断。
- 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.
它为以后的工作提供了坚实的起点。类似于第一条。此外,如果你在几个月后重新回到某一个项目,你会忘记大部分代码是如何工作的。测试可以提醒你,如果你突然弄乱来一些东西,测试代码库可以是一个参考。
- 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.
它迫使你去写更加简洁的代码。长且复杂的函数是很难测试的。简单的测试和清晰的表达自然的产生更短和更具可读性的应用代码。
- 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