Fork me on GitHub
#testing
<
2019-12-07
>
Nick McCurdy04:12:54

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

seancorfield05:12:17

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.

seancorfield05:12:23

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

seancorfield05:12:51

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 https://guide.clojure.style/#testing

seancorfield05:12:10

Yeah, just looked that up. Disappointing.

seancorfield05:12:46

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

seancorfield05:12:56

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 🙂

seancorfield05:12:06

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

plexus11:12:14

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.

tanzoniteblack18:12:54

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)