Where did you learn to unit test? How did you learn?

Christopher Blunck blunck at gst.com
Tue Apr 29 18:14:41 EDT 2003


"andrew cooke" <andrew at acooke.org> wrote in message news:<mailman.1051634984.9521.python-list at python.org>...
> imho help with refactoring is by far the biggest bonus of static typing
> (in a language like java; in more functional languages refactoring tends
> to be more about adding higher order functions which, again, are helped by
> static typing, but the experience is somewhat different).  this may depend
> on your development environment, of course - at the moment i'm working
> with a somewhat ugly codebase that needs a lot of refactoring.

That's a very good point.  And it's something that I do miss in
Python.  I guess you could argue that if you have solid unit test
coverage that this becomes a non-issue (the classes that use the old
interface will no longer work correctly).


> a key point to making tests work in java is abstracting out test
> specifications.  most of the work of test classes is adding frameworks
> that allow cases to be specified in a compact manner.  once that is done,
> adding test cases is very simple (for example, i verify trees from a
> parser against xml specifications - the framework is fairly complex, but
> once done it's easy to test many different cases).  this is particularly
> important in java because the language itself (the syntax) is fairly
> inflexible and verbose.

Very funny because I just made this point not more than 1 hour ago to
a coworker.  He was struggling through writing the first unit test in
a subsystem that has never been unit tested.  His frustration
surrounded your exact argument - adding the initial unit test
framework is difficult, but makes incremental test development
trivial.  Point in case is that his TestData class (which produces
objects that he uses to test) is about 500 lines of code.  His actual
unit test is about 20 - 40 lines of code.  But now that the framework
is there, lots more 20 - 40 line unit tests can be written.  This is
(of course) in Java, but it translates to python as well.


> this approach (lead by example) seems to me much better than forcing
> people to use tests.  after all, they're not always appropriate.  and
> there's no surer way of making someone dislike somethig than forcing them
> to do it.  also, generally, leading by example seems to get you a "better"
> team.

Yup.  And of course - there's only so much you can teach a team that
isn't interested in learning.  I'd add a corollary to your statement:
it's equally important to know when you've done all you can for a team
and it's time to move on.




More information about the Python-list mailing list