[Baypiggies] TDD and mocking

Glen Jarvis glen at glenjarvis.com
Fri Jan 27 20:11:10 CET 2012


Hy gave a good newbie nugget last night. I've been doing more TDD and am
really excited about it. But, I struggle with mocking.

My question last night was how to mock properly. The example that I gave
was for my current project (A mechanical turk and Django smash up). Most of
my project is really basic -- just interfacing with other libraries, etc.
There are pieces that I need to test -- like some admin actions, Django
management commands, etc.

I've tried to use Mock libraries, but haven't gotten over the hump. Let me
re-ask the question now.

Would it be "cool" or "uncool" if I made my equivalent Python class for a
HIT, Assignment and Answer (these are equivalent classes from Boto)? The
class would be a very basic/thin slice of what Amazon/Boto would provide.
And, then when I try to mock, I inject my models into my project
(hand-wavy somehow via monkey patching)?

Now that I write this, would it be better to instantiate the results that
Boto would present and inject those into a mocked response from Amazon? I'm
bumping around in the dark on this and just haven't gotten past the hump to
really mock well.

I think I'm going to just give my best college try and then send a link to
the project, asking for feedback/review on how I could have done it better.
Any offline advice would be appreciated. The project is currently "written"
but I consider it my first draft -- and already have found mistakes that
would have been found by doing TDD first. I'd like to remove code, build
failing tests, put in each part of code, and let the design drive.

Wiki: https://github.com/glenjarvis/djurk/wiki/Quick-Start

Code: https://github.com/glenjarvis/djurk

Warmest Regards


Glen
P.S. I got some good advice last night from JJ and others. But, as I
thought of my question further, I don't think I need to go as far as the
WSGI layer as I just need to simulate the objects that would be received
from the function call.... thoughts?
--
Things which matter most must never be at the mercy of things which matter
least.

-- Goethe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20120127/01fb34ab/attachment.html>


More information about the Baypiggies mailing list