Skip to Content
成為卓越程式設計師的38項必修法則
book

成為卓越程式設計師的38項必修法則

by Pete Goodliffe
May 2015
Intermediate to advanced
376 pages
5h 48m
Chinese
GoTop Information, Inc.
Content preview from 成為卓越程式設計師的38項必修法則
98
| 第十一章:測試時間
4.
回到第 1 步驟並重複執行,直到寫出所有功能都能通過的測試程式為止。
這是一個強大、精簡的回饋回路。它通常被簡稱為
紅綠重構
週期,以紀念單位測試工具
會將失敗的測試顯示為紅色的進度條,通過的測試顯示為綠色條。
就算你不遵守優先測試原則,也請你簡短回饋回路,並在每一段程式或它的附近編寫單
位測試。單位測試真的可以協助“驅動”我們的設計:它不但可以確保每一個東西的功
能都正確,也可以避免錯誤回歸,它也是瞭解產品怎麼使用某個類別 API 的好方法—如
何輕鬆且簡潔。這是非常寶貴的回饋。測試程式也可以當成實用的文件,說明如何使用
類別,在它完成時。[Page-92]
重點
在你編寫
被測試的程式碼時,編寫測試程式。不要之後再編寫測試程
式,否則你的測試程式將不會有同樣的效果。
這個早期測試、經常測試的做法可套用到單位、整合及系統層級。就算你的專案沒有自
動系統測試的基礎結構,你也可以承擔責任,並使用單位測試程式來驗證你所寫的程
式。它成本很低,而且因為良好的程式結構,也很簡單
2
另一個重要的測試程式編寫時間是當你必須修改產品程式的 bug 時。請不要急忙地開始
修改程式,先編寫一個失敗的單位測試來說明 bug 的原因。有時編寫這種測試程式的動
作可以讓其他相關的程式缺陷顯示出來。接著套用你的修改,並讓測試通過。把這個測
試程式放入測試池,用來確保 bug 不會再度出現。
何時執行測試
只要瞄一眼,你就可以看出很多端倪。
- Yogi Berra
顯然,如果你使用 TDD 來開發,會在開發各個功能時 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

精通機器學習|使用Python

精通機器學習|使用Python

Sarah Guido, Andreas C. Mueller
Java性能优化实践:JVM调优策略、工具与技巧

Java性能优化实践:JVM调优策略、工具与技巧

Benjamin J. Evans, James Gough, Chris Newland

Publisher Resources

ISBN: 9789863475699