Unit Testing in Lisp
.
Source Location
The
CLforJava lisp test-driver, and lisp tests can be found in the source repository, along with the "suite" files.
Function directories:
Test Case Layout
*Every individual test case will be stored solitarily in a list which contains all the test cases
The format of each test case is as follows:
The example given is the test case for the function CAAR which takes the CAR (which is the first element of a list) of the CAR of a list.
For example (CAAR '( (1 2 3) (4 5 6) (7 8 9) )) would take the CAR of ( (1 2 3) (4 5 6) (7 8 9) )
which is the list (1 2 3)
It would than take the CAR of this list (1 2 3)
which is 1
So (CAAR '( (1 2 3) (4 5 6) (7 8 9) )) would return 1
In order to write a test case for this function you would use the following format:
( defun test-case-sample () ( equalitytest ( functionname args ) returnvalue ) &optional seffects )
- EQUALITYTEST
- whatever variation of equal, eql, etc. you choose to use to compare the expected and actual ouput of the function that is being tested
- FUNCTIONNAME
- name of the function you'd like to test
- ARGS
- a list of args to pass it
- RETURNVALUE
- expected return value
- SEFFECTS
- optional a function specific test to determine expected sideffects. Should return a generalized boolean
So in the case of CAAR the test case would appear as:
(defun caar-test-1 () (equal (caar '((1 2 3) (2 3 4) (3 4 5))) 1))
*programmers will want to make sure which equal, eql, etc. variation is appropiate for each individual case
How to add your Test Case
- Check to see if the function you are testing already has a file under the correct directory. (e.g. <function>-test.lsp)
- Situation 1- There is an existing test file
Simply add your new case to the existing file
- Situation 2- There is no test file
Create a new file: <function>-test.lsp, add it to the correct directory
Add the function to the defvar list inside the respective suite file
How to add a Suite
- Create a new directory (e.g. CLforJava\test\src\lisp\<function-type>\)
- Add a suite file in the main directory (e.g. CLforJava\test\src\lisp\<function-type>-suite.lsp\)
- Add another section to CLforJava\build\BuildEntities\runLispTest.xml
- Note: Reference the conses-suite.lsp & conses section in runLispTests.xml for examples
Status
The current status of the testing suites can be viewed on the QAStatus page
http://clforjava.org/twiki/bin/view/DevEnvironment/QAStatus
--
AveryScott - 31 Jan 2008 --
MatthewMerricks - 12 Feb 2008 --
RyanMoore - 07 May 2010
Topic revision: r10 - 2010-05-07 - 14:47:46 -
RyanMoore