liveBook · Manning

Test fixture

As explained in Clojure: The Essential Reference

A test fixture is setup and teardown code that establishes and cleans up the context required by a test.

A test fixture is setup and teardown code that establishes and cleans up the context required by a test. In clojure.test, fixtures wrap test execution so shared preparation and cleanup happen consistently. section 22.9

A fixture typically follows this contract:

  • Accept the test function as an argument. section 22.9
  • Run preparation before invoking the test function, then perform cleanup afterward. section 22.9
  • Register with use-fixtures, choosing :each to apply the fixture around every test. section 22.9

A per-test fixture

Define (defn setup [tests] (println "### before") (tests) (println "### after")), register it with (use-fixtures :each setup), and run the suite. Two tests produce before/after output twice, followed by a passing summary. section 22.9

How Clojure: The Essential Reference covers it

How deep it goes
Explains callback wrapping, setup-before and teardown-after ordering, and per-test registration without expanding into broader fixture design.
Examples
Uses a setup function printing before and after markers around two tests registered with use-fixtures :each.
What you can do after
Operate/configure it with clojure.test by registering a wrapper around each test.
How it connects
Connects setup and teardown code with tests, testing contexts, and test runners.

Also explained in

Compare how 10 books explain test fixture →

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.