Fork me on GitHub
Nick McCurdy04:12:54

Is it best practice to use :refer :all when requiring clojure.test or should I use :alias instead?


It's considered acceptable to use :refer :all with clojure.test (and the namespace that represents the system-under-test) but I prefer explicit :refer [deftest is ...] as needed to support your tests, and :as for the SUT, because with linters that gives you better feedback.


For a while, I used to :as sut for the namespace under test so it was clear what parts of the tests were actually things being tested, as opposed to other things that exist just to support the tests. But I found that a bit stilted so I've moved away from that in the last few years.

Nick McCurdy05:12:20

That’s what I felt but the docs didn’t seem clear to me, thanks


I'm not sure how much the community style guide talks about testing...

Nick McCurdy05:12:34

Not much, just about file and namespace structure


Yeah, just looked that up. Disappointing.


I think a lot of "best practice" in Clojure is both oral and rather dynamic 😐

Nick McCurdy05:12:36

I could understand recommended style depending on the test framework

Nick McCurdy05:12:46

Though i’d imagine :refer :all is popular for most testing packages


FWIW, when I'm using expectations.clojure.test (my preferred framework), I still use explicit :refer [defexpect expect ,,,] as needed and :as for the namespace under test 🙂


(I probably ought to update the documentation to use :refer [,,,] instead of :refer :all to encourage the former)


I personally prefer :refer :all for Clojure.test. it's a dsl that I expect to be available in a test namespace. I don't want to have to think about whether I've already referred testing, run, or are.


I prefer this too, but I've somewhat had to get out of this habit due to clojurescript's refusal to support :refer :all (