Mock Objects

stéphane ducasse ducasse at iam.unibe.ch
Mon Jun 26 20:57:46 UTC 2006


Chad

You know what would be great?
If you could write by pasting some of your code in a text editor and  
share that with us.
I would like to add some material to my Sunit tutorial and I could  
use your example.

Stef

On 23 juin 06, at 15:48, Chad Nantais wrote:

> Frank & Jason,
>
> I don't need anything too deep right now.  I just need to be able to
> create an object that mocks up a simple API for a remote service.
>
> I found this page and used it to create exactly what I needed.
> http://www.cincomsmalltalk.com/userblogs/malby/SingleView.ssp? 
> showComments=true&forPrinter=true&entry=3293316866
>
> I'm also using it to test non-networked code now too.  For example,
> when I am writing unit tests for Cart, and I want to test the
> Cart>>total, which adds prices of CartItem instances that are in the
> cart, I just mock up the CartItem instances and make them return some
> number when sent #price.  This is great because I can really isolate
> the Cart class that's being tested without it being dependant on
> having a fully-working CartItem class.
>
> Thanks for your help.
>
> Chad
>
> On 6/23/06, Jason Rogers <jacaetevha at gmail.com> wrote:
>> While this mock layer is good for many applications, I think it's
>> probably too deep for what Chad is dealing with.  Chad -- you should
>> be able to mock out the service itself and inject that into your
>> application code.  While I haven't done this in a Smalltalk
>> application I have successfully and easily done it in *many*
>> applications in other languages.
>>
>> Jason
>>
>> On 6/23/06, Frank Shearar <frank.shearar at angband.za.org> wrote:
>> > "Chad Nantais" <chad at clearwaterassociates.ca> wrote:
>> >
>> > > Hi.
>> > >
>> > > Could someone please direct me to a Squeak project (or some
>> > > documentation) that uses mock objects in its tests, specifically
>> > > dealing with testing network code like a web service.  I'm  
>> looking for
>> > > a way to speed up some unit tests that hit a remote service.
>> >
>> > It's by no means fully functional, but you might want to look at
>> > MockSocketStream. That SHOULD be in Squeak-3.8 and up, seeing as  
>> I wrote it
>> > in 2004.
>> >
>> > Having a mock network layer not only lets you speed up tests, it  
>> also allows
>> > you to disregard all the lovely things that can go wrong in the  
>> network. You
>> > can run your tests knowing that you're not going to get red  
>> everywhere
>> > because your colleague tripped over your fly lead, or is  
>> fiddling with a
>> > patch panel in the next room. And, of course, a mock network  
>> layer lets you
>> > INJECT errors :)
>> >
>> > I do intend adding to the MockSocketStream at some stage, but my  
>> plate's too
>> > full for the next several months.
>> >
>> > frank
>> >
>> >
>> >
>>
>>
>> --
>> Jason Rogers
>>
>> "Where there is no vision, the people perish..."
>>     Proverbs 29:18
>>
>>
>




More information about the Squeak-dev mailing list