Public Variables and Functions
*load-tests*
dynamic varTrue by default. If set to false, no test functions willbe created by deftest, set-test, or with-test. Use this to omittests when compiling or loading production code.
Added in Clojure version 1.1
Source
*stack-trace-depth*
dynamic varThe maximum depth of stack traces to print when an Exceptionis thrown during a test. Defaults to nil, which means print the complete stack trace.
Added in Clojure version 1.1
Source
are
macroUsage: (are argv expr & args)
Checks multiple assertions with a template expression.See clojure.template/do-template for an explanation oftemplates.Example: (are [x y] (= x y) 2 (+ 1 1) 4 (* 2 2))Expands to: (do (is (= 2 (+ 1 1))) (is (= 4 (* 2 2))))Note: This breaks some reporting features, such as line numbers.
Added in Clojure version 1.1
Source
assert-any
functionUsage: (assert-any msg form)
Returns generic assertion code for any test, including macros, Javamethod calls, or isolated symbols.
Added in Clojure version 1.1
Source
assert-predicate
functionUsage: (assert-predicate msg form)
Returns generic assertion code for any functional predicate. The'expected' argument to 'report' will contains the original form, the'actual' argument will contain the form with all its sub-formsevaluated. If the predicate returns false, the 'actual' form willbe wrapped in (not...).
Added in Clojure version 1.1
Source
compose-fixtures
functionUsage: (compose-fixtures f1 f2)
Composes two fixture functions, creating a new fixture functionthat combines their behavior.
Added in Clojure version 1.1
Source
deftest
macroUsage: (deftest name & body)
Defines a test function with no arguments. Test functions may callother tests, so tests may be composed. If you compose tests, youshould also define a function named test-ns-hook; run-tests willcall test-ns-hook instead of testing all vars.Note: Actually, the test body goes in the :test metadata on the var,and the real function (the value of the var) calls test-var onitself.When *load-tests* is false, deftest is ignored.
Added in Clojure version 1.1
Source
deftest-
macroUsage: (deftest- name & body)
Like deftest but creates a private var.
Added in Clojure version 1.1
Source
do-report
functionUsage: (do-report m)
Add file and line information to a test result and call report.If you are writing a custom assert-expr method, call this functionto pass test results to report.
Added in Clojure version 1.2
Source
file-position
functionUsage: (file-position n)
Returns a vector [filename line-number] for the nth call up thestack.Deprecated in 1.2: The information needed for test reporting isnow on :file and :line keys in the result map.
Added in Clojure version 1.1
Deprecated since Clojure version 1.2
Source
function?
functionUsage: (function? x)
Returns true if argument is a function or a symbol that resolves toa function (not a macro).
Added in Clojure version 1.1
Source
get-possibly-unbound-var
functionUsage: (get-possibly-unbound-var v)
Like var-get but returns nil if the var is unbound.
Added in Clojure version 1.1
Source
inc-report-counter
functionUsage: (inc-report-counter name)
Increments the named counter in *report-counters*, a ref to a map.Does nothing if *report-counters* is nil.
Added in Clojure version 1.1
Source
is
macroUsage: (is form) (is form msg)
Generic assertion macro. 'form' is any predicate test.'msg' is an optional message to attach to the assertion.Example: (is (= 4 (+ 2 2)) "Two plus two should be 4")Special forms:(is (thrown? c body)) checks that an instance of c is thrown frombody, fails if not; then returns the thing thrown.(is (thrown-with-msg? c re body)) checks that an instance of c isthrown AND that the message on the exception matches (withre-find) the regular expression re.
Added in Clojure version 1.1
Source
join-fixtures
functionUsage: (join-fixtures fixtures)
Composes a collection of fixtures, in order. Always returns a validfixture function, even if the collection is empty.
Added in Clojure version 1.1
Source
report
dynamic multimethodNo usage documentation available
Generic reporting function, may be overridden to plug indifferent report formats (e.g., TAP, JUnit). Assertions such as'is' call 'report' to indicate results. The argument given to'report' will be a map with a :type key. See the documentation atthe top of test_is.clj for more information on the types ofarguments for 'report'.
Added in Clojure version 1.1
Source
run-all-tests
functionUsage: (run-all-tests) (run-all-tests re)
Runs all tests in all namespaces; prints results.Optional argument is a regular expression; only namespaces withnames matching the regular expression (with re-matches) will betested.
Added in Clojure version 1.1
Source
run-test
macroUsage: (run-test test-symbol)
Runs a single test.Because the intent is to run a single test, there is no check for the namespace test-ns-hook.
Added in Clojure version 1.11
Source
run-test-var
functionUsage: (run-test-var v)
Runs the tests for a single Var, with fixtures executed around the test, and summary output after.
Added in Clojure version 1.11
Source
run-tests
functionUsage: (run-tests) (run-tests & namespaces)
Runs all tests in the given namespaces; prints results.Defaults to current namespace if none given. Returns a mapsummarizing test results.
Added in Clojure version 1.1
Source
set-test
macroUsage: (set-test name & body)
Experimental.Sets :test metadata of the named var to a fn with the given body.The var must already exist. Does not modify the value of the var.When *load-tests* is false, set-test is ignored.
Added in Clojure version 1.1
Source
successful?
functionUsage: (successful? summary)
Returns true if the given test summary indicates all testswere successful, false otherwise.
Added in Clojure version 1.1
Source
test-all-vars
functionUsage: (test-all-vars ns)
Calls test-vars on every var interned in the namespace, with fixtures.
Added in Clojure version 1.1
Source
test-ns
functionUsage: (test-ns ns)
If the namespace defines a function named test-ns-hook, calls that.Otherwise, calls test-all-vars on the namespace. 'ns' is anamespace object or a symbol.Internally binds *report-counters* to a ref initialized to*initial-report-counters*. Returns the final, dereferenced state of*report-counters*.
Added in Clojure version 1.1
Source
test-var
dynamic functionUsage: (test-var v)
If v has a function in its :test metadata, calls that function,with *testing-vars* bound to (conj *testing-vars* v).
Added in Clojure version 1.1
Source
test-vars
functionUsage: (test-vars vars)
Groups vars by their namespace and runs test-var on them withappropriate fixtures applied.
Added in Clojure version 1.6
Source
testing
macroUsage: (testing string & body)
Adds a new string to the list of testing contexts. May be nested,but must occur inside a test function (deftest).
Added in Clojure version 1.1
Source
testing-contexts-str
functionUsage: (testing-contexts-str)
Returns a string representation of the current test context. Joinsstrings in *testing-contexts* with spaces.
Added in Clojure version 1.1
Source
testing-vars-str
functionUsage: (testing-vars-str m)
Returns a string representation of the current test. Renders namesin *testing-vars* as a list, then the source file and line ofcurrent assertion.
Added in Clojure version 1.1
Source
try-expr
macroUsage: (try-expr msg form)
Used by the 'is' macro to catch unexpected exceptions.You don't call this.
Added in Clojure version 1.1
Source
use-fixtures
multimethodNo usage documentation available
Wrap test runs in a fixture function to perform setup andteardown. Using a fixture-type of :each wraps every testindividually, while :once wraps the whole run in a single function.
Added in Clojure version 1.1
Source
with-test
macroUsage: (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, ignoringthe tests.
Added in Clojure version 1.1
Source
with-test-out
macroUsage: (with-test-out & body)
Runs body with *out* bound to the value of *test-out*.
Added in Clojure version 1.1
Source