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.
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...
Not much, just about file and namespace structure https://guide.clojure.style/#testing
Yeah, just looked that up. Disappointing.
I think a lot of "best practice" in Clojure is both oral and rather dynamic 😐
I could understand recommended style depending on the test framework
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
(https://groups.google.com/d/msg/clojurescript/SzYK08Oduxo/MxLUjg50gQwJ)