Testing¶
Unit tests can be run via the current REPL session and/or an external test runner.
Test coverage reports show how much of the code has unit test coverage.
Performance testing helps select appropriate functions and algorithms to used by timing multiple calls and reporting the results. The choice of function can have a significant effect on the critical paths in the code.
Unit tests¶
Unit test libraries and configuration. The Clojure standard library includes the clojure.test namespace, so no alias is required.
:env/test- addtestdirectory to classpath
Test runners¶
Practicalli Clojure: Unit testing covers many aspects of testing for projects.
Kaocha is the main test runner used by Practicalli as it is simple to use and easily configurable to create an effective test workflow.
Run unit tests in a project which are defined under the test path.
| Command | Description |
|---|---|
clojure -X:test/run |
run tests with the Kaocha comprehensive test runner for Clojure (same as :test/kaocha) |
clojure -X:test/watch |
run tests in watch mode using Kaocha test runner for Clojure (same as :test/kaocha-watch) |
clojure -X:test/cognitect |
Cognitect Clojure test runner |
clojure -X:test/coverage |
Cloverage clojure.test coverage report |
clojure -M:test/cljs |
ClojureScript test runner (Kaocha) |
:lib/kaocha alias adds kaocha as a library to the class path, enabling scripts such as kaocha-runner.el to run Kaocha test runner from Emacs Cider
A
test.ednconfiguration file can be used with the :test/run alias instead of using various aliases defined above
Performance testing¶
Performance testing tools for the REPL
Use the aliases with either -M or -X flags on the Clojure command line.
clojure -M:performance/benchmark:repl/rebel
(require '[criterium.core :refer [bench quick-bench]])
(bench (expression-to-test))
Performance test a project in the REPL
clojure -M:performance/benchmark:repl/rebel
(require '[practicalli/namespace-name]) ; require project code
(in-ns 'practicalli/namespace-name)
(quick-bench (project-function args))
- :performance/memory-meter - memory usage
Use the aliases with either -M or -X flags on the Clojure command line.
In the REPL: