V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
pilishen
V2EX  ›  问与答

你应该使用测试驱动开发的 7 个原因

  •  
  •   pilishen · 2018-04-28 20:00:53 +08:00 · 1577 次点击
    这是一个创建于 2435 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本文翻译自 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:

    至少:

    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.

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

    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

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2706 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:42 · PVG 20:42 · LAX 04:42 · JFK 07:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.