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." 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 [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
Hi Panu,
Usually the first place to look for packages ("libraries") is SqueakSource. To use is just go to http://www.squeaksource.com , hit click in "Projects" and search for "Mock" in the text field. There are some packages for using Mock Objects, after selecting a package you may see some of them include documentation in the wiki page (see the palette). You may comment the experience if you choose a package. Best regards, Hernán 2010/8/31 Panu Suominen <[hidden email]>: > 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." > > 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 > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users > _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
In reply to this post by Panu Suominen-3
Hello Panu,
Welcome to Pharo! The free Pharo By Example book ( http://pharobyexample.org/ ) has a chapter (7) on SUnit, the Smalltalk Unit Testing framework. This should get you started. The best place to learn about Smalltalk is by looking at code in your current image. There should be thousands of unit test there that can serve as examples. I am not sure how to answer your specific question. If you need a MockObject it seems that you should just define it in your test package and use it right there. I can see several examples in my image. Search for classes *Mock* Sven On 31 Aug 2010, at 21:01, Panu Suominen 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." > > 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 > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
In reply to this post by Panu Suominen-3
On Tue, Aug 31, 2010 at 9:01 PM, Panu Suominen <[hidden email]> wrote: Hi all, 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 _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
Thank you for your responses. I thought I checked squeaksource, but
apparently I did not. Maybe I should get more sleep. :D -- Panu _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
Hello,
try Mocketry http://squeaksource/mocketry See wiki tab for examples. Latest version should work in pharo 1.1 2010/9/1 Panu Suominen <[hidden email]> Thank you for your responses. I thought I checked squeaksource, but _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
Sorry, reference is http://www.squeaksource.com/Mocketry.html
2010/9/1 Denis Kudriashov <[hidden email]> Hello, _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
In reply to this post by Denis Kudriashov
2010/9/1 Denis Kudriashov <[hidden email]>:
> try Mocketry http://squeaksource/mocketry Thanx. Tested it earlier today and Mocketry seems to be just what I was looking for. -- Panu _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
Free forum by Nabble | Edit this page |