testing

Testing tools, testing philosophy & methodology...
2017-02-14T15:55:08.000069Z

Hi all! I recently finished writing a test using with-redefs, which I think is a pretty awesome piece of Clojure technology. But a colleague mentioned that using with-redefs is frowned upon. As far as I can tell the main concern is that if multiple tests are running at once, then the variable is redefined for all threads. Outside of this, is there much concern? To the best of my knowledge, tests with leiningen are single threaded, so is there a risk? If so, what else should I look into?

donaldball 2017-02-14T16:12:06.000070Z

My general preference is to abstract all my side-effecting code behind protocols, test the side-effecty impl explicitly, and to reify instances of the protocol for testing code that uses the protocol.

donaldball 2017-02-14T16:14:34.000071Z

with-redefs is adequate for a fn here or a fn there of course. Abstractions aren’t always worth it.

dottedmag 2017-02-14T16:28:57.000072Z

@surreal.analysis with-bindings is safer, if the vars are dynamic.

dottedmag 2017-02-14T16:29:06.000073Z

And if you care about thread-safety, yes.

2017-02-14T16:31:54.000074Z

Thanks all! I understand the risks, and I’m using it to redefine a function from a library, so I think I’ll stick with it, but I really appreciate the clarification @donaldball and @dottedmag