Ví dụ được trình bày trong chương cuối cùng, chúng tôi đã không vượt qua bất kỳ đối số phương pháp bản địa, cũng không phương pháp bản địa trở lại. Phương pháp bản địa chỉ đơn giản là in một tin nhắn và quay trở lại. Trong thực tế, hầu hết các chương trình sẽ cần phải vượt qua đối số cho các phương pháp bản địa, | mock objects We need lots of different but similar objects The problem right now b that we have a sequence like this Order Processor Test DB Utilities proCessOrderi Here s where the roWem is forjac d ff ent tyj r the a different Gst sb return right kind of g ft tard J ẹroCessữrder saveớrderí . save ơ Y qc with Certain values TesVioodDBAcce - .or getóơgcld mt 6iftCard save Cicard 6 ftCird void fake-save the éịC ix all fake but order process Has ic tall these methods e an -fle-entabon of DBAeeessor TesUnsuff It lenWB Accessor get CJgild mt giftcard Qve CQird 6 fiCird void Test nvahdDBAccessor t C y Id ẬftCard save Cicard ẶftCa -d void What if we generated objects instead of writing aii these DÕÃccessor implementations whal if ttf had a tool III a liatnruiiik that we could ell to i rate a new object conforming to a main interlace like DBAccessor and dial would Iwhavr in a certain way. like returning a gift card with a zero balance provided a certain input was passed in v our test Code can use this object like any other . it Elements PBAtecssor and looks just like a real class that you d write yourself- y r testmg code tells the framework what it dsỸ7 I want a DBAccessof imptementation that returns a Giftcard With a zero balance please Here san object. if you call getGCO with a value of 12345. Il will do just what you want Mock Object I . _ Framework Most languages have a framework just like this just google mock objects. 304 Chapter B test-driven development A mock object stands in for real objects There s really no need lor three diflerent accessors. all ol whit 11 create a new GiftCard object and populate It with dtllerent data. I hat 3 a lol ol extra code to instantiate a Giftcard and call some setter methods. Since we have an interlace that describes what each of these implementations should look like wc can take advantage of a mock object framework Io do the hraxy lilting. Instead of implementing all of hr classes ourselves. we t an give the framework hr