with-test

clojure.test

  • (with-test definition & body)
Takes any definition form (that returns a Var) as the first argument.
Remaining body goes in the :test metadata function for that Var.

When *load-tests* is false, only evaluates the definition, ignoring
the tests.

1 Example top

  • ;with test is the same as using {:test #((is...)(is...))} in the meta data of the function.
    
    (:use 'clojure.test)
    
    (with-test
        (defn my-function [x y]
          (+ x y))
      (is (= 4 (my-function 2 2)))
      (is (= 7 (my-function 3 4))))
    
    (test #'my-function)            ;(test (var my-function))
    => :ok
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/test.clj:585 top

(defmacro with-test
  "Takes any definition form (that returns a Var) as the first argument.
  Remaining body goes in the :test metadata function for that Var.

  When *load-tests* is false, only evaluates the definition, ignoring
  the tests."
  {:added "1.1"}
  [definition & body]
  (if *load-tests*
    `(doto ~definition (alter-meta! assoc :test (fn [] ~@body)))
    definition))
Vars in clojure.test/with-test:
Used in 0 other vars

Comments top

No comments for with-test. Log in to add a comment.