TE

Clojure Testing

Clojure testing conventions with clojure.test, generative testing, and REPL-driven development

Details

Language / Topic
clojureClojure
Category
Testing

Rules

balanced
- Use `clojure.test` with `deftest` and `is` macros — name test functions with a `-test` suffix matching the tested function.
- Use `clojure.spec.test.alpha/check` with `test.check` to run generative tests against spec-instrumented functions automatically.
- Place tests in `test/` mirroring `src/` namespace structure — `test/myapp/core_test.clj` for `src/myapp/core.clj`.
- Use `testing` blocks inside `deftest` to group related assertions with a descriptive label — they appear in failure output to pinpoint failures.
- Use `with-redefs` to replace `def`-bound functions with test doubles in unit tests — prefer it over `alter-var-root` for temporary bindings.
- Use `clojure.test.check.generators` with `gen/fmap`, `gen/bind`, and `gen/such-that` to build domain-specific data generators.
- Use `kaocha` as the test runner for unified output, parallel test execution, and plugin-based reporting in CI.