mocking propertys

168 views
Skip to first unread message

gary

unread,
Jul 26, 2010, 12:06:02 PM7/26/10
to mockito-python
is it possible to mock methods with the @property annotation or
propertys and propertys calculated by functions


regards
gary

Serhiy Oplakanets

unread,
Jul 27, 2010, 3:20:57 AM7/27/10
to mockito-python
In short: NO.
You can mock setters and deleters, but not getters, as current
implementation doesn't allow that.
However I'm not sure this is feasible to do with mockito. Did you
consider creating a mock class by hands?

gary

unread,
Jul 27, 2010, 3:54:42 AM7/27/10
to mockito-python


On Jul 27, 8:20 am, Serhiy Oplakanets <ser...@oplakanets.com> wrote:
> In short: NO.
> You can mock setters and deleters, but not getters, as current
> implementation doesn't allow that.

ok thats an interesting comment what is the shortcoming that doesn't
allow mocking of getters...

> However I'm not sure this is feasible to do with mockito. Did you
> consider creating a mock class by hands?

Ah I have just started to use mockito to avoid that ;-)


regards and manyt hanks for the comments
gary

Serhiy Oplakanets

unread,
Jul 27, 2010, 4:02:16 AM7/27/10
to mockito-python
> ok thats an interesting comment what is the shortcoming that doesn't
> allow mocking of getters...

Getters are not really executed as functions, and mockito can answer
only to call (parentheses)
This is both due to properties implementation and mockito
implementation. Check out the code.

> Ah I have just started to use mockito to avoid that ;-)
Wrong way to go if you ask me. One should always prefer using hand-
rolled mocks. They're always closer to domain model and easier to read/
understand.
Your mocking tool should only help you in cases when hand-rolled mocks
become complex and hard to implement.

Maybe those will inspire you:
http://blog.objectmentor.com/articles/2010/01/23/mocking-mocking-and-testing-outcomes
http://blog.objectmentor.com/articles/2009/10/28/manual-mocking-resisting-the-invasion-of-dots-and-parentheses
http://www.markhneedham.com/blog/2010/01/15/tdd-hand-written-stubs-vs-framework-generated-stubs/

Christoph Neuroth

unread,
Aug 19, 2010, 5:40:46 AM8/19/10
to mockito-python
> Ah I have just started to use mockito to avoid that ;-)
Me too. How did you dend up testing your properties?
Chris
Reply all
Reply to author
Forward
0 new messages