In Clojure the unit under test is the function. Unit test coverage should test all public function that form the API of their respective namespace.
clojure.test namespace provides a unit testing framework and is included in the Clojure library, so is available in all Clojure projects.
Test runners are used to run one or more tests in a project.
Principles for writing test code
testnamespace for each
deftestfunction for each function under test
isassertions for one function
- Group assertions in
testingand provide a meaningful description of that grouping, adding more information when reviewing test failures especially for larger code bases.
Project structure with tests
By convention, separate
test directories are used to hold the source code and the code that tests the source code.
For each source code file in
src there should be a corresponding file in test with the same name and
For example, code to test the
src/codewars/rock_paper_scissors.clj is saved in the file
Create Projects from templates
Templates typically include a parallel
src directory structure. The
clj-new tool has build it templates (app, lib) and will create
test directories in the projects it creates.
clojure -A:clj-new app practicalli/rock-paper-scissors-lizard-spock