The 'right' way to run unit tests in Clojure
clojure, testing
Solution
I also run tests in my REPL. I like doing this because I have more control over the tests and it's faster due to the JVM already running. However, like you said, it's easy to get in trouble. In order to clean things up, I suggest taking a look at tools.namespace.
In particular, you can use `clojure.tools.namespace.repl/refresh` to reload files that have changed in your live REPL. There's also`refresh-all` to reload all the files on the classpath.
I add tools.namespace to my `:dev` profile in my `~/.lein/profiles.clj` so that I have it there for every project. Then when you run `lein repl`, it will be included on the classpath, but it wont leak into your project's proper dependencies.
Another thing I'll do when I'm working on a test is to require it into my REPL and run it manually. A test is just a no-argument function, so you can invoke them as such.
Problem
Currently, I define the following function in the REPL at the start of a coding session: ``` (defn rt [] (let [tns 'my.namespace-test] (use tns :reload-all) (cojure.test/test-ns tns))) ``` And everytime I make a change I rerun the tests: ``` user=>(rt) ``` That been working moderately well for me. When I remove a test, I have to restart the REPL and redefine the method which is a little annoying. Also I've heard bad rumblings about using the `use` function like this. So my questions are: - Is using `use` this way going to cause me a problem down the line? - Is there a more idiomatic workflow than what I'm currently doing?