testing

Testing tools, testing philosophy & methodology...
Tim Robinson 2021-01-09T10:53:52.049300Z

Hi all. I've just written my first clojure.test test 🙂 but I've noticed than using (run-all-tests) in the repl lists out "Testing xxx" for every namespace, so I have to wade through 500 lines of irrelevant output to find out the test that failed. Is there any simple way to get round that? It's just a small one-man project so I don't want to set up any complicated CI

vemv 2021-01-09T17:12:04.049900Z

(clojure.core/->> (clojure.core/all-ns)
                  (clojure.core/filter (clojure.core/fn [n]
                                         (clojure.core/->> n
                                                           clojure.core/ns-publics
                                                           clojure.core/vals
                                                           (clojure.core/some (clojure.core/fn [var-ref]
                                                                                {:pre [(clojure.core/var? var-ref)]}
                                                                                (clojure.core/-> var-ref clojure.core/meta :test))))))
                  (clojure.core/sort-by clojure.core/pr-str)
                  (clojure.core/apply clojure.test/run-tests))
I have this as a IDE snippet (e.g yasnippet) that I can expand in the repl

Tim Robinson 2021-01-09T18:16:24.050100Z

thanks I'll try that out 🙂

robertfw 2021-01-09T19:44:26.050600Z

I've used weavejester/eftest on a few projects, it's a fairly minimal test runner, you might want to take a look at that. https://github.com/weavejester/eftest

seancorfield 2021-01-09T21:28:30.050900Z

I have hot keys bound to a) essentially (clojure.test/run-tests *ns*) to run all the tests in the current namespace and b) code that constructs a test ns name from the current ns (e.g., by sticking -test on it), requiring it, and then running tests in that ns.

seancorfield 2021-01-09T21:29:47.051100Z

https://github.com/seancorfield/vscode-clover-setup/blob/develop/config.cljs#L112-L117 -- it tries -test first and then -expectations because we have a lot of tests at work that use https://github.com/clojure-expectations/clojure-test (because I prefer that syntax, but wanted it to be compatible with all the clojure.test tooling).