liveBook · Manning

Test-var

As explained in Clojure: The Essential Reference

test-var is a clojure.test function that executes the test function recorded in a var's metadata.

test-var runs the test function stored under the :test key in a Var’s metadata. Pass a Var object, commonly obtained with #'test-name. section 22.9

deftest arranges this metadata automatically, so test-var provides a direct way to execute one named test rather than an entire namespace. section 22.9

Run one test

(deftest sqrt-test (is (= 2 (sqrt 4)) "Expecting 2")) (test-var #'sqrt-test) ;; FAIL in () ;; Expecting 2 ;; actual: (not (= 2 2.000000000000002))

How Clojure: The Essential Reference covers it

How deep it goes
Defines the Var and metadata contract, then demonstrates execution and failure reporting without detailing runner internals.
Examples
Uses sqrt-test to demonstrate direct execution and assertion diagnostics.
What it assumes
Assumes familiarity with Vars and deftest while showing that deftest records the executable test function in metadata.
What you can do after
Apply it via clojure.test to execute a named test Var and inspect assertion failures.
How it connects
Connects test-var with deftest, test-vars, test-ns, test-all-vars, run-tests, and run-all-tests.

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.