For a while I have known, that testing with default arguments is not the best idea. I mean, it's better than not testing at all, but it's still not a very good test.
Take the following case (which cost me a few hours):
Two systems, one running a web service in Microsoft .NET 1.1, the other a java application written with Netbeans. They communicate their data structures by serializing them in xml. So far nothing out of the ordinary. But since we are talking about two systems, testing needs to include multiple roundtrips. And that makes unittests that serialize and then deserialize on one platform a logical choice. And if you do those unittests with default arguments (i.e. create the data structure, serialize it, deserialize it, and then check the values), guess what happens ?
You catch nothing !
It so happens that the deserializers will create a data structure, which will have DEFAULT VALUES (pardon my screaming, I'm yelling at myself for being so stupid).
So the moral of this story is, if you test, test at least once with non-default values.
P.S. 10 minutes after I rewrote the code, I found another bug (with the test). One element was omitted in the serialization !! Test, Test, Test
No comments:
Post a Comment