A unit test framework for Common Lisp
I was reading Peter Seibels book Practical Common Lisp a couple of months ago and got inspired by his very simple testing framework. I thought how hard can it be to expand that into a “real” framework in the SUnit tradition. Well, it wasn’t really hard, but it did take a couple of months anyway.
So here is my attempt at a unit test framework for Common Lisp. I’ll call it 1.0 when there is some proper documentation.
There is very little documentation at this point but if you are familiar with the Test::Unit framework from Ruby it should not be too hard to get started with this. There is also an example use of the framework in a sub-directory in the distribution.
Basically, you define a test case with the DEFINE-TEST-CASE macro. This macro defines a CLOS class with the same name as the test case. You could just define your test cases with DEFCLASS but the macro wraps up the definitions of the SET-UP and TEAR-DOWN methods so it’s probably easier to use the macro.
Test cases are identified by being subclasses of the TEST-CASE class.
The individual tests are then defined with the DEFINE-TEST macro. This macro defines methods with the same names as the tests so you would think that it would be just as easy to define the tests with DEFMETHOD instead. But, the framework depends on a couple of special variables, which are automatically set if you define your tests with the macro.
The assertions you use in the tests are called ASSURE-* instead of assert so as not to clash with the standard ASSERT.
Finally, to run the tests you use the RUN-TESTS function. When you tell it to run all tests for a test case it uses introspection to find all methods whose names start with TEST- so for this to work all tests should follow this naming convention.
The framework use the MOP, which is known to differ between Common Lisps. I have tested this with current SBCL and OpenMCL on Mac OS X.
The license is the MIT license.