XP中的TDD是什么?測試驅動開發?測試驅動設計?
?
?
Test-Driven Development
http://www.xprogramming.com/xpmag/whatisxp.htm#test
Extreme Programming is obsessed with feedback, and in software development, good feedback requires good testing. Top XP teams practice "test-driven development", working in very short cycles of adding a test, then making it work. Almost effortlessly, teams produce code with nearly 100 percent test coverage, which is a great step forward in most shops. (If your programmers are already doing even more sophisticated testing, more power to you. Keep it up, it can only help!)
It isn't enough to write tests: you have to run them. Here, too, Extreme Programming is extreme. These "programmer tests", or "unit tests" are all collected together, and every time any programmer releases any code to the repository (and pairs typically release twice a day or more), every single one of the programmer tests must run correctly. One hundred percent, all the time! This means that programmers get immediate feedback on how they're doing. Additionally, these tests provide invaluable support as the software design is improved.
在上面的圖中,列出的的是XP的12個團隊實踐。Test-Driven Development是其中之一。
Kent Beck 的著作TDD(Test Driven Development) 中詳細講述了測試驅動開發。
在XP中測試是一種設計,不是簡單的為了測試你的功能是否實現。測試先行一個目的
是可以在代碼編寫之前,保證測試已經寫好;其實這些測試的另一個目的就是設計接口,
保證接口在以后的修改過程中能夠滿足測試(設計)。當你有意或無意修改接口的時候,你必須同時
修改測試
要改動接口的時候,也應該是先修改測試,再修改代碼。而不是修改代碼等著報錯再修改
測試(設計)
。(測試必須100%通過才能進行下一個功能),這樣測試也是在提醒你,接口已經改變。
實際上,設計已經改變。當你修改單元測試的時候,可能就會遭到抱怨。為什么?你修改了設計
,別人的代碼是依賴你修改前的測試(設計),那么新的測試(設計)中的變動可能要影響到
別人已有的代碼。
?
當你使用TDD的時候一定要說明是測試驅動開發還是測試驅動設計。這兩者是有區別的。測試驅動
開發,是通過測試定義所要開發的功能的接口,然后實現功能的開發過程。對于測試驅動設計,在XP中似乎
已經消失了,而是被測試驅動開發所取代。另外在XP中有用于描述設計的,SimpleDesign ,Design Improvement.
在XP中測試是一種設計,設計之后才有開發,這也就是為什么要測試先行了。
在XP中測試是一種文檔,用于描述設計。