發表文章

目前顯示的是 12月, 2009的文章

C#單元測試--使用Pex

今天看到一篇MSDN上的新文章,在 介紹有關單元測試的資訊 。 微軟團隊最近發表了一套可以配合Visual Studio來使用的單元測試軟體-- Pex 。這套軟體可以針對您所開發完成的程式碼,實際分析其中的程式碼語意,自動地產生所需的單元測試範本及相關的程式。 在Pex的網站中,有許多詳細的說明,而且還有 介紹的影片可線上觀看 。 在程式開發過程中,需求不斷地在變更的事實,算是不可否認的現象之一了。就算再如何地做好需求訪談、分析,也無法避免未來開發過程中,或進入維護階段時,所需面對的功能修正的問題。 為了能確保每次進行的軟體功能修正都能正確無誤,而且就算在加入新功能時,也能同時確保原有功能的正常的話,使用測試導向的開發模式是勢在必行的了。 當然,要程式開發人員再多費心思去撰寫測試程式或準備測試範本的話,可能會多佔用他們的寶貴時間,造成一般開發人員在開發過程中,都不太會去花時間在測試的方面。 有了Pex的輔助,可以將測試流程大量地自動化的話,一定可以改善開發流程及品質的。 Pex使用了參數化單元測試(Parameterized Unit Test -- PUT)的技術。以下節錄自Pex的說明文件: A unit test is a method without parameters represents a test case which typically executes a method of a class-under-test with fixed arguments and verifies that it returns the expected result. A parameterized unit test (PUT) is the straightforward generalization of a unit test by allowing parameters. PUTs make statements about the code’s behavior for an entire set of possible input values, instead of just a single exemplary input value. A unit test is a method without parameters represent