Flying With Python (Strong versus Weak Typing)
Roy Smith
roy at panix.com
Thu Mar 13 08:33:32 EST 2003
"Delaney, Timothy C (Timothy)" <tdelaney at avaya.com> wrote:
> I don't claim to follow the XP way, but I am a strong believer in unit tests.
I've found a few very non-XP uses for unit tests. For example,
sometimes they can be used to force people to document their work.
A while back, we embarked on a project to add unit tests to a library of
utility functions which had been in production use for a while. We
found a few bugs, but more importantly (in my mind), it forced people to
go back and carefully define and document the behavior of each function.
There was a function called isValidIpAddress. Turns out the original
author had one thing in mind for the definition of "valid", and other
people had used the function thinking it did something different. The
issue had come up at various times in reviews of code that used this
function, but somehow we always managed to argue ourselves out of really
figuring out what it was supposed to do.
I wrote a unit test for the function, using my understanding of what
"valid" meant. The existing code failed the unit test. Now we had
something which was harder to ignore. Instead of vaguely-remembered
arguments at code reviews, we now had a "FAILED" message in our face
that we had to do something about. Either the code had to be changed to
pass the unit test I had written, or somebody had to write a precise
enough spec for what the function was SUPPOSED to do, and then I would
change the unit test to match the spec.
If you don't know what it's supposed to do, you can't tell if it's
working or not.
More information about the Python-list
mailing list