你應該使用測試驅動開發的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

相關文章
相關標籤/搜索