什麼是 Mock Objects?
在 MSDN(http://msdn.microsoft.com/msdnmag/issues/04/10/NMock/) 中的說明:Traditionally, unit testing terminology has included the concepts of drivers and stubs.傳統來說,Unit Testing 包含 drivers 及 stubs 兩個觀念。As an implementation of a driver, I use NUnit (currently at version 2.2), and for stubs I use NMock (currently at version 1.1) to create dynamic mock objects at run time.如果要實作 driver 會使用 NUnit,如果是實作 stubs 的話,則使用 NMock 來即時動態產生 mock 物件。It is worth noting that NMock uses reflection to create mock implementations of interfaces at run time, so to use NMock it is necessary to code against interfaces instead of implementations.值得注意的是 NMock 使用 reflection 來即時依照 interfaces 產生實作的 mock,所以在使用 NMock 時,必須依照 interfaces 而非 implementations 來寫程式。(註:Reflection(或稱為RTTI)已成為主流語言中必備的特色,其主要用途在於執行時期提供型別資訊)
0 Comments:
Post a Comment
<< Home