On Tue, Aug 31, 2010 at 9:01 PM, Panu Suominen
<[email protected]>wrote:

> Hi all,
>
> I am quite new to smalltalk and I am probably having "cultural"
> difficulties. I mostly work with Java.
> So it is possible that there is trivial answer for my question or my
> question is just wrong. But here
> it goes.
>
> I am implementing object that should make a call to some other object.
> I need to test that the
> caller works correctly based on the return value it receives. So
> basically the code and the test
> looks like this and I need to fill the XXXX part:
>
> Object>>doSomething
>    result:=innerObject makeACall.
>    "based on result do something"
>
> Test>>test
>    "get bogus object for testing from somewhere"
>    mockForTest := XXXX.
>    (Object new)
>        innerObject: mockForTest.
>        doSomething.
>    "check that something was done."
>
>
Something hacky can be do something like this:


Test>>test
   "get bogus object for testing from somewhere"
SystemChangeNotifier uniqueInstance doSilently: [
        mockClass := Object
            subclass: #MockForTest
            instanceVariableNames: ''
            classVariableNames: ''
            poolDictionaries: ''
            category: self class category.

MockForTest compile: 'makeACall
   ^ ''holaaaa'' '
 ].
   mockForTest := MockForTest new.
   (Object new)
       innerObject: mockForTest.
       doSomething.
   "check that something was done."


I didn't check with an email, but it should work. You can also add
#makeACAll  in an already existing class. Suppose I do it in TestCase:

TestCase compile: 'makeACall
   ^ ''holaaaa'' '



  mockForTest := TestCase new.
   (Object new)
....

Of course, a real project for mocking would be muuuch better.



> I am used to resolve this kind of problems using mock objects. I
> tought it would be easy to implement
> in smalltalk too because it is dynamic language. However with my limited
> searches I did not found much usable code or examples how to do it.
> So, my question is: is there some easy way to resolve this problem or
> does it require
> a bigger library? If it does, is there a library already for that?
>
> --
> Panu
>
> _______________________________________________
> Pharo-users mailing list
> [email protected]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
>
_______________________________________________
Pharo-users mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users

Reply via email to