Testing Side Effects in Clojure

In the Clojure world there’s one prevailing principle: simplicity. And there’s no exception when it comes to testing.

Let’s say we have a function that inserts a record into a relational database, let’s say this function uses yesql and looks like this:

So usually at this point you import some mocking/stubbing library and things are kind of hairy in there, but you don’t really care because it all seems to work. In clojure, stubbing things is part of the core library: with-redefs

And that’s all there is to it, you’re redefined function can be as long and complected as you need it to be.

Like what you read? Give Sean Walker a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.