liveBook · Manning

Test-ns

As explained in Clojure: The Essential Reference

test-ns is a clojure.test function that runs tests in a namespace and honors its test hook when present.

test-ns runs the tests associated with a namespace, prints a summary, and honors a namespace-level test-ns-hook when one is defined. Without a hook, it behaves almost like test-all-vars; with a hook, it executes the hook instead of discovering every test var. section 22.9

Selecting tests with a namespace hook

(ns composable-tests) (require '[clojure.test :refer [is deftest]]) (deftest fail-a (is (= 1 (+ 2 2)))) (deftest fail-b (is (= 1 (+ 2 2)))) (deftest fail-c (is (= 1 (+ 2 2)))) (defn test-ns-hook [] (fail-a) (fail-c)) (test-ns 'composable-tests) ;; {:test 2, :pass 0, :fail 2, :error 0} The hook runs fail-a and fail-c, while fail-b is skipped.

How Clojure: The Essential Reference covers it

How deep it goes
Defines ordinary discovery, hook substitution, and summary behavior, but does not detail test execution internals.
Examples
Demonstrates selecting fail-a and fail-c through test-ns-hook while reporting two failures.
What it assumes
Assumes familiarity with namespaces, deftest, test vars, and basic clojure.test execution.
What you can do after
Operate/configure namespace-level test execution and selectively compose tests through test-ns-hook.
How it connects
Connects test-all-vars, test hooks, fixtures, test-var, and run-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.