[TIP] testing: why bother?

Laura Creighton lac at openend.se
Wed Mar 23 06:34:36 PDT 2011


I think that the most important reason to write tests is so that they
can write them _first_, and the code _later_.  This will change the way
they write code, so that they won't produce these large, self-contained,
too-tightly coupled messes, which just happen to work, and which are
a nightmare to refactor because they don't decompose nicely.

However, telling them that they should write tests because their code
is crappy is unlikely to have the positive effect you want.

So tell them that they should write tests because it is best way to
document exactly what a piece of code is supposed to do, by design,
as opposed to the things it just happens to do but is irrelevant to
its function.  That way, when somebody, often not the original writer
of the code wants to change it, he knows exactly what it is that he
has to keep working.  And the failures will tell him when he hasn't
done this properly.

But if 'how do you _know_ this code is correct' hasn't caused them to
write tests already, then I suspect they are hopeless.

Laura




More information about the testing-in-python mailing list