Dependency Injection can be used similarly to the way one would in Java. The only difference is that dependencies are now functions as opposed to objects.
This is the method I have taken the most advantage of. You simply bind all functions that the function under test uses. Like so...
Here, the create function use the method create in the interactor namespace. So, with the binding in place, when the create function calls interactor/create, it will actually call the mock function. In this case, the mock function just stores the data given to it and increments a call count. However, the possibilities are endless.
(def mock-called-count (atom 0)) (def mock-called-content (atom nil)) (defn mock [& args] (swap! mock-called-count #(inc %)) (reset! mock-called-content args)) (binding [interactor/create mock] (create @customer))
So, with these two great methods of mocking in Clojure, who needs a mocking framework?