liveBook · Manning

Deftest

As explained in Clojure: The Essential Reference

deftest is a clojure.test macro that defines a named test function and registers it for test execution.

deftest defines a named Clojure test and makes it available to clojure.test execution. It generates a function in the current namespace, whose test-var metadata supports direct execution. section 22.9

Define and run a test

(deftest sqrt-test (is (= 2 (sqrt 4)) "Expecting 2")) (test-var #'sqrt-test) The assertion reports a failure when the computed result differs from 2.

How Clojure: The Essential Reference covers it

How deep it goes
Explains generated functions and macroexpansion, while deferring comprehensive test-suite design.
Examples
Uses sqrt tests, macroexpansion, direct test-var calls, grouped assertions, and namespace-wide runners.
What you can do after
Builds named executable tests and runs them individually, by namespace, or through a test suite.
How it connects
Connects deftest with macros, test-var, assertions, namespaces, and test runners.

Related concepts

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.