This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-01
Channels
- # adventofcode (93)
- # announcements (44)
- # asami (23)
- # aws (1)
- # babashka (48)
- # beginners (112)
- # calva (26)
- # cider (57)
- # clj-kondo (17)
- # cljfx (5)
- # cljs-dev (21)
- # clojure (124)
- # clojure-europe (19)
- # clojure-hungary (40)
- # clojure-nl (3)
- # clojure-spec (7)
- # clojure-uk (3)
- # clojurescript (3)
- # cursive (81)
- # datalog (11)
- # events (21)
- # exercism (1)
- # fulcro (37)
- # graalvm (1)
- # introduce-yourself (8)
- # jobs (1)
- # lsp (1)
- # malli (5)
- # membrane-term (17)
- # minecraft (3)
- # nextjournal (5)
- # off-topic (14)
- # other-lisps (14)
- # polylith (58)
- # reagent (16)
- # reclojure (3)
- # reitit (6)
- # remote-jobs (1)
- # shadow-cljs (55)
- # spacemacs (15)
- # testing (2)
- # tools-build (7)
- # tools-deps (191)
Asked this question in #clojure before noticing this channel, is there a resource for best practices testing clojure?
I think the same rules for testing on other languages apply to Clojure:
1. Avoid testing "internal state" and "implementation details", test more the behavior
2. Try to make the test convey information. Instead of (is (= {...big-map...} (my-fun)))
, try to use (is (= valid-user (my-fun)))
3. Try to use a better matching library, like expectations for example. My choice is matcher-combinators
There are some that I also add for Clojure:
1. Avoid fixtures. It's hard to get them right and you lose some of the REPL capabilities like running a fragment of your test. I prefer to write macros that will do the setup and teardown
2. If you're using ClojureScript, be aware of async testing - it's REALLY hard. I would recommend a library that handles that for you
3. Property testing is amazing, but it's a different kind of test. It does not replace integration/unit-ish tests
I think the same rules for testing on other languages apply to Clojure:
1. Avoid testing "internal state" and "implementation details", test more the behavior
2. Try to make the test convey information. Instead of (is (= {...big-map...} (my-fun)))
, try to use (is (= valid-user (my-fun)))
3. Try to use a better matching library, like expectations for example. My choice is matcher-combinators
There are some that I also add for Clojure:
1. Avoid fixtures. It's hard to get them right and you lose some of the REPL capabilities like running a fragment of your test. I prefer to write macros that will do the setup and teardown
2. If you're using ClojureScript, be aware of async testing - it's REALLY hard. I would recommend a library that handles that for you
3. Property testing is amazing, but it's a different kind of test. It does not replace integration/unit-ish tests