An alternative to clojure.test, aiming to be feature-rich and easily extensible.
More explicit instructions can be found in the installation, usage, and configuration pages, but here's a quick rundown:
Add it to your deps.edn or project.clj:
{:aliases
{:test {:extra-deps {io.github.noahtheduke/lazytest {:mvn/version "2.1.0"}}
:extra-paths ["test"]
:main-opts ["-m" "lazytest.main"]}}}
In a test file, import with:
(require '[lazytest.core :refer [defdescribe describe expect it]])
And then write a simple test:
(defdescribe seq-fns-test
(describe keep
(it "should reject nils"
(expect (= '(1 2 3) (keep identity [nil 1 2 3]))))
(it "should return a sequence"
(expect (seq? (seq (keep identity [nil])))))))
From the command line:
$ clojure -M:test
lazytest.readme-test
seq-fns-test
#'clojure.core/keep
√ should reject nils
× should return a sequence FAIL
lazytest.readme-test
seq-fns-test
#'clojure.core/keep
should return a sequence:
Expectation failed
Expected: (seq? (seq (keep identity [nil])))
Actual: nil
Evaluated arguments:
* ()
in lazytest/readme_test.clj:11
Ran 2 test cases in 0.00272 seconds.
1 failure.
clojure.test has existed since 1.1 and while it's both ubiquitous and useful, it has a number of problems:
is tightly couples running test code and reporting on it.are is strictly worse than doseq or mapv.clojure.test/report is ^:dynamic, but that leads to being unable to combine multiple reporters at once, or libraries such as Leiningen monkey-patching it.test-ns-hook does not count).testing calls aren't real contexts, they're just strings.There exists very good libraries like Expectations v2, kaocha, eftest, Nubank's matcher-combinators, Cognitect's test-runner that improve on clojure.test, but they're all still built on a fairly shaky foundation. I think it's worthwhile to explore other ways of being, other ways of doing stuff. Is a library like lazytest good? is a testing framework like this good when used in clojure? I don't know, but I'm willing to try and find out.
Other alternatives such as Midje, classic Expectations, and speclj attempted to correct some of those issues and they made good progress. However, some (such as Midje) relied on non-list style (test => expected) and most don't worked well with modern repl-driven development practices (as seen by the popularity of the aforementioned clojure.test-compatible Expectations v2).
I like the ideas put forth in Alessandra's post above about Lazytest and hope to experiment with achieving them 14 years later, while borrowing heavily from the work in both the Clojure community and test runners frameworks in other languages.
Lazytest supports Clojure (1.10+) and Babashka (v1.12.208+). It does not support Clojurescript or other flavors at this time.
Originally by Alessandra Sierra.
Currently developed by Noah Bogart.
Licensed under Eclipse Public License 1.0
Can you improve this documentation? These fine people already did:
Stuart Sierra, Noah Bogart & j1mr10rd4nEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |