Test driven development

Virgil Dupras hardcoded.software at gmail.com
Thu Jan 24 16:20:23 CET 2008


On Jan 24, 7:37 am, ajcpp... at gmail.com wrote:
> Hi
>
> Sorry if this is a bit off topic but as unit testing is such a
> cornerstone of python development I thought a few of you may be able
> to share your knowledge/experiences.
>
> I like the concept of TDD but find it difficult to put into practice
> most of the time. I think this primarily because I tend to like top-
> down development and functional/object decomposition and TDD feels
> more like a bottom-up approach.
>
> So my question is when approaching a project that you want to employ
> test driven development on how and where do you start? And also if
> anyone uses top-down design with TDD I would be interested in how you
> do it (does it involve lots of mock objects/ is the first test you
> write the last one to pass)?
>
> Thanks
>
> Andy

I know what you mean by top-down vs. bottom-up and I used to have the
same dilemma, but now I would tend to agree with Albert. Your issue
with top-down or bottom-up is not relevant in TDD. The only thing that
is relevant is to reach your current milestone as soon as possible,
without caring about what you're going to do in the milestone after
that.

Not so long ago, I took the "bottom-up" approach to TDD, which was a
mistake because it leads to over-engineering (the end result is not so
bad since it's over-engineering that has good test coverage :) )

Roy: While mocking is good to have tests well organized (instead of
having a huge pile of tests at the highest level), "over-
mocking" (mocking everything, early) leads to, I think, a design that
is too rigid. What if a new spec reveals that the current design of a
large subset of your classes has to be re-done? All your mocking and
the test below them, they all have to be "brought up" to the highest
level of tests so you can re-organize your code. Since doing this is a
lot of work, and usually messing with tests is a lot more dangerous
than messing with the code itself, you would tend to stay with your
old design, even if it's not the optimal design for the task you need
to do.

Virgil



More information about the Python-list mailing list