I am writing a clojure.test unit test for a rather large function in my application. This function makes several calls to db and external REST services and does some computation. for example, my function to be tested is like so
(defn myfunc [id]
(let[
w (some-security-call id)
x (some-db-call id)
y (some-REST-call x)
z ( some-audit-call y)
]
(-> y :somekey )))
for the purpose of testing this method, I want to stub out or redefine "some-audit-call" and "some-security-call". Clojure's with-redefs-fn only redefines one method at one time.
Is there a standad way to mock out multiple functions used in a function being unit tested?
with-redefsworks on as many functions as you want. Here is a redacted example from my actual production tests.if you need to redefine a function that is used by another function that you want to redefine then you have to nest the calls to with-redef. this sometimes causes people to think that with-redefs only works with one function.
You likely don't want to use
with-redefs-fnunless you know you have a specific reason.