testing

Testing tools, testing philosophy & methodology...
2019-12-07T04:59:54.023500Z

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

seancorfield 2019-12-07T05:04:17.025100Z

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.

seancorfield 2019-12-07T05:06:23.026600Z

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.

2019-12-07T05:11:20.027Z

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

seancorfield 2019-12-07T05:11:51.027400Z

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

2019-12-07T05:12:34.027700Z

Not much, just about file and namespace structure https://guide.clojure.style/#testing

seancorfield 2019-12-07T05:13:10.028100Z

Yeah, just looked that up. Disappointing.

seancorfield 2019-12-07T05:13:46.028800Z

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

2019-12-07T05:14:36.029100Z

I could understand recommended style depending on the test framework

2019-12-07T05:14:46.029500Z

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

seancorfield 2019-12-07T05:15:56.030400Z

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 🙂

seancorfield 2019-12-07T05:17:22.030600Z

( https://github.com/clojure-expectations/clojure-test )

seancorfield 2019-12-07T05:20:06.031400Z

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

plexus 2019-12-07T11:41:14.033500Z

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.

tanzoniteblack 2019-12-09T18:10:54.033600Z

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)