Unit testing - suitable for all development?

John J. Lee jjl at pobox.com
Sun Mar 7 19:28:49 EST 2004


kylotan at hotmail.com (Kylotan) writes:
[...]
> on their presence). Sure, technically I could create dummy objects to
> pass in that have do-nothing functions, but then I break most of
> Creature's accessors, which are implemented in terms of delegating to
> the other objects. In turn this would make the tests meaningless.

It seems that way to start with, but they're far from meaningless.

Read some of the tutorials on unit testing if you want to reassure
yourself that your unit tests (especially those using mock objects)
are just as 'trivial' as other peoples'.


> None of this makes testing any harder or less useful in catching bugs;
> it just means that it ends up being an almost straight duplication of
> my normal code, with the input handling stripped out! It hardly seems
> worth the effort.

That's right: you write the test, you think "this test code is so
trivial it hardly seems worth the effort".  Then you run them, and you
think "OK, maybe it's not so trivial".  OK, most (but not all) of the
bugs you find in that process are in the tests, not the code.  Just as
important, though, it makes you think about what you're writing,
reducing coupling.  Then, later, you break your code, and the trivial,
obvious, unit test saves a lot of time.  Then, later, if you
reimplement your interface, and spend a good solid chunk of time
rapidly fixing bug after bug after bug in the new implementation (each
bug revealed by the tests), you'll wonder if it would even have been
*possible* to reimplement it without the unit tests.

Still, I'm told some people write good code without unit tests.  I
don't really understand how.


John



More information about the Python-list mailing list