Browse Clojure Foundations for Java Developers

Mocking and Stubbing in Clojure

Prefer passing functions/data over heavy mocks; use with-redefs sparingly.

Mocking exists in Clojure, but idiomatic Clojure often needs less of it because you can pass behavior directly as a function and keep most logic pure.

Practical patterns that Java developers usually like:

  • pass dependencies as a map of functions ({:now now-fn :fetch fetch-fn})
  • keep interop/I/O behind a small adapter namespace
  • test pure transforms directly without stubbing the world

Tools like with-redefs can be useful, but they temporarily change global var roots—so use them deliberately and keep the scope tight.

In this section

Revised on Friday, April 24, 2026