Re: [Pyunit-interest] Mock Objects (was Aid requsted regarding test-first-design)
Brought to you by:
purcell
From: Dave K. <dk...@bl...> - 2001-11-25 23:35:46
|
At 15:36 24/11/01 -0500, Michal Wallace wrote: >Hey Dave, > >Thanks for writing it. I've read through the code and it's >pretty slick. :) > >I have thought about extending it so that it could recognize >parameters. > >In java, I got used to EasyMock ( http://easymock.org ), >where you actually have two objects - a mock object and a >controller. You call the mock object, and then tell the >controller what result it should return. I think the way you >do this in python is a whole lot cleaner, but I miss being >able to test for parameters. > >Cheers, > >- Michal http://www.sabren.net/ sa...@ma... I know the Python Mock module does not fit the definition of Mock Objects as given in the article by Tim MacKinnon & Steve Freeman (http://www.sidewize.com/company/mockobjects.pdf), since the Mock object does not do any verification of the calls made, but leaves that up to the caller. I did think about adding some sort of internal checking, but since I didn't need it at the time I decided that YAGNI & DTSTTCPW applied and left it out. It is possible to test the parameters of a specific method by subclassing the Mock class and adding that method, but if you have to do that for every method it negates the benefit of having the Mock class in the first place. The biggest problem with the module as it stands is that it lets the user call any method on it, regardless of whether the call would be legal in the class being mocked. It should be fairly easy to extend it to check this by initialising it with a list of legal method names (and perhaps their allowable parameters), but there is a danger of making the whole thing so complex to use that it becomes simpler to hand code a specific mock class from scratch. I have just had a look at EasyMock, and it would be possible to do something similar to it in Python, passing in the class to be mocked and letting the Mock class extract all the legal methods and their parameters. Perhaps one day I will get round to adding it... Regards, Dave Kirby |