Common Lisp Unit

For unit tests in Common Lisp you could do worse than start with the RT package available from the CMU AI repository:

http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/testing/rt/0.html

The format of a test is very very simple:

 (deftest <test-name>
    <form-to-evaluate>
   <expected answer>)

e.g.

 (deftest simple-sockopt-test
   ;; test we can set SO_REUSEADDR on a socket and retrieve it, and in
   ;; the process that all the weird macros in sockopt happened right.
   (let ((s (make-inet-socket :stream (get-protocol-by-name "tcp"))))
     (setf (sockopt-reuse-address s) t)
     (sockopt-reuse-address s))
   t)

Note that the two results are compared with EQUAL. I find that almost always I end up doing the real comparison in the test form and check it against T as the expected answer

--DanBarlow

Of course, that assumes the comparison operator returns T for true, which isn't guaranteed for many of the builtin comparison operators. Doing the comparison in that way also obscures the output on failure. You are told it failed, but not what the actual result was. --PaulDietz


[See TestingFramework for others.]


EditText of this page (last edited August 17, 2004) or FindPage with title or text search