Macro DEFTEST
Syntax:
deftest description &key category test-fn compare-fn output-fn output-form input-fn input-form => test
Arguments and Values:
description---a string
category---a string
test-fn---a function
compare-fn---a function
output-fn---a function
output-form---a form
input-fn---a function
input-form---a form
Description:
deftest defines a test to be run by CLUnit.
The test is automatically registered with CLUnit and is afterwards available to
be run by CLUnit.
The test is identified by its description, but the user can also specify a category into
which the test is to be placed. All tests from a given category can be run using the function
run-category. In
addition, a specific test or all tests can be run using the functions
run-named-test or
run-all-tests respectively.
In addition to its identification and categorization attributes, a test
also has four
functional attributes: its input function, its test function,
its output function, and its comparison function. These
attributes are used when the test is run to determine
whether the test has passed or failed.
The test is run using the following procedure:
- The input function of the test is evaluated to provide a set of values, collected by multiple-value-list.
- The test's test function is applied to values returned by the input function
and the resulting set of output values is collected using multiple-value-list.
- The output function of the test is evaluated to give a set
of values that are also collected using multiple-value-list.
- The test's comparison function is used to compare the lists resulting from the
evaluation of the test function and output function.
- The output of the comparison function is returned as the value of the test.
If the comparison function
returns t, the test is said to have passed. If the test returns nil or
an error is encountered while running the test, the test has failed.
In addition to its description parameter, deftest will
accept a variety of other keyword parameters:
- :category is used to specify the category for the test. If left unspecified, the
test is categorized under the category *UNCATEGORIZED*.
- :test-fn specifies the test function to be used by the test. If unspecified,
the test function defaults to #'(lambda () t).
- :compare-fn specifies the comparison function to be used by the test.
If not specified, it defaults to #'equal.
- :input-fn and :input-form parameters are used to specify
the input function
used by the test. If :input-fn is specified, its value is used as the test's
input function. If unspecified,
the value of the :input-form parameter is used to create a function returning
that value to be used as the input function for the test. Lambda expressions used or
formed by these parameters are created within the lexical environment within which the
deftest form is located. If neither of these parameters
is provided, the test function is assumed to take no input parameters.
- :output-fn and :output-form parameters are used to specify
the output function
used by the test. If :output-fn is specified, its value is used as the test's
output function. If unspecified,
the value of the :output-form parameter is used to create a function returning
that value to be used as the output function for the test. Lambda expressions used or
formed by these parameters are created within the lexical environment within which the
deftest form is located. If neither of these parameters
is provided, the test function defaults to #'(lambda () t).
See Also:
run-named-test, run-all-tests,
run-category, remove-test
Notes:
Redefining a test with a given name will replace the original test with the new one.
Redefining a test with a given name will move the test to the category specified in
the redefinition.
Frank A. Adrian
Last modified: 12 July, 2001 14:59