From: Nat Pryce Date: 2002-09-23T18:31:23+09:00 Subject: Re: The problem with run-time type checking On Sun, 2002-09-22 at 19:36, Philip Mak wrote: > I'm asking when I write a function that depends on its arguments to be a > specific type, how can I make them produce informative stack dumps if the > arguments are the wrong type? I don't see how unit testing would help the > person writing a library function. Testing that an object makes correct calls to a library is not the responsibility of the library writer, it is the responsibility of the programmer who is using the library. A programmer should test that their objects implement their postconditions and invariants correctly, and that their objects meet the preconditions of other object that they call. One way to do this is to mock up the environment of the object in order to assert that outgoing calls are correct when the object is exercised in a test case. This kind of testing is easiest if libraries are written as collections of classes that are used through *composition*, rather than through inheritance. That is, an object should use your library through an object reference, rather than through a module of free-floating functions. This way, programmers using your library can create mock versions of your classes in their unit tests to ensure that the correct values are being passed out of their objects. If you really want to help clients of your library, you can provide a suite of mock objects that can be used for unit testing client code. Cheers, Nat. -- Dr. Nathaniel Pryce, Technical Director, B13media Ltd. Studio 3a, 22-24 Highbury Grove, London N5 2EA, UK http://www.b13media.com