FiveAM

FiveAM is a Test Framework whose goal is to be as simple as possible. This Development tool was created because the author, Marco Baringer, felt that the other testing frameworks required the user to write too much "stuff" before writing the actual tests.

Some useful user comment is linked from the project home page.

has the usual features you would expect from an xUnit style test framework [...] presents a more lispish macro interface.

Distinguishing Characteristics

  1. assert-equal, assert-eql, assert-true, etc. have been replaced by the single is macro which inspects its argument to determine how to test equality
  2. Tests and test suites are named via symbols, this allows tests with the same name to peacfully live together (in different packages), and makes removing or runing single tests easy.
  3. !, !! and !!! functions for easily re-running recently run tests.
  4. inter test dependencies

Download ASDF package from http://common-lisp.net/project/bese/tarballs/fiveam-latest.tar.gz


Example:

CL-USER> (def-suite my-suite :description "My Example Suite")
CL-USER> (in-suite my-suite)
CL-USER>
(test my-tests
  "Example"
  (is (= 4 (+ 2 2)) "2 plus 2 wasn't equal to 4 (using #'= to test equality)")
  (is (= 0 (+ -1 1)))
  (signals
      (error "Trying to add 4 to FOO didn't signal an error")
    (+ 'foo 4))
  (is (= 0 (+ 1 1)) "this should have failed"))
CL-USER> (run!)
...f
 Did 4 checks.
    Pass: 3 (75%)
    Skip: 0 ( 0%)
    Fail: 1 (25%)

Failure Details: -------------------------------- MY-TESTS [Example]: this should have failed. --------------------------------

I'm pretty new at lisp, but I found the def-fixtures in 5am triggered the following: :Redefining CL-USER::A-FIXTURE in deflookup-table named IT.BESE.FIVEAM::FIXTURE

The reason for this is the following EVAL-WHEN in DEF-FIXTURE (fixture.lisp):

  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (get-fixture ',name) (cons ',args ',body))
     ',name))

I changed it to the following to get SBCL to load without warnings. All that is done is removing the fixture before generating the new one. I got the idea from the null def-fixture in the test cases in 5am's repository.

  ;;; Modified from http://common-lisp.net/project/bese/repos/fiveam/src/fixture.lisp
(defmacro def-fixture (name args &body body)
  "Defines a fixture named NAME. A fixture is very much like a
macro but is used only for simple templating. A fixture created
with DEF-FIXTURE is a macro which can use the special macrolet
&BODY to specify where the body should go.

See Also: WITH-FIXTURE

*note* that this overrides the default 5am DEF-FIXTURE. 5am's DEF-FIXTURE does not remove the old instance of the fixture." `(eval-when (:compile-toplevel :load-toplevel :execute) (rem-fixture ',name) (setf (get-fixture ',name) (cons ',args ',body)) ',name))

;;; Fixtures get used like this: (def-fixture test/fixture (&optional (a 1) (b 2)) (&body))

(5am:with-fixture test/fixture () (list a b))

;;This is kind of neat in a way, as if one of the defaults in ;;the fixture is off, you only need to define that one. Any ;;valid lambda list can be passed as it is processed by ;;destructing bind.

;;A real test using our fixture looks something like: (test (fixture-test1 :fixture test/fixture) (is (= a 1)) ; passes (is (= b 2))) ; passes

;;If we wanted to override the value of a, but leave b ;;(and potentially many more) alone do the following: (test (fixture-test2 :fixture (test/fixture 7)) (is (= a 7)) ; passes (is (= b 2))) ; passes

-- Nixeagle

This page is linked from: 5am   armish   liards   Marco Baringer   test framework  

CLiki pages can be edited by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively