Cider test deps edn projects
Configure Unit Testing for deps.edn projectsλ︎
Cider test runner is a convenient way to run Clojure unit tests, using the same REPL for evaluating source code.
The test
directory must be included in the classpath when running the REPL, as test code is evaluated in the running REPL.
An alias should be used to include the test
directory. The test
path should not be part of the main :paths
configuration, otherwise test code would be included in the jar or uberjar package and deployment.
A .dir-locals.el
file can include any number of aliases when using Cider jack-in.
{% tabs practicalli="practicalli/clojure-deps-edn", deps="Manual deps.edn projects" %}
{% content "practicalli" %}
Practicalli user level aliasesλ︎
practicalli/clojure-deps-edn user-level configuration contains several aliases for running tests within the CIDER jack-in REPL.
:env/test
adds the test
directory to the class path and enables CIDER test runner to find the test code. This is the only alias required if using Cider test runner.
:lib/kaocha
add the kaocha library to the class path, so kaocha can be used instead of CIDER test runner.
Other aliases can be used with the :env/test
alias to support cider-connect approach:
:repl/cider
include the nrepl and cider-nrepl libraries and starts an nREPL server connected to the REPL
:repl/rebel
run Rebel Readline, providing a rich terminal UI for the REPL
{% content "deps" %}
Add test directoryλ︎
Add the :env/dev
alias to the project deps.edn
file or user level configuration.
Terminal REPL UIs with nREPLλ︎
Use cider-connect
to connect to the Clojure REPL process started in a terminal window with the following command:
Use the :repl/rebel-nrepl
alias to also run a Rebel UI for the REPL in the terminal.
Alias to run a simple Terminal UI REPL with nREPL supportλ︎
Run a REPL using nREPL server that starts an nREPL server, enabling CIDER to connect via cider-connect-clj
:repl/cider
{:extra-deps {nrepl/nrepl {:mvn/version "0.9.0"}
cider/cider-nrepl {:mvn/version "0.27.4"}}
:main-opts ["-m" "nrepl.cmdline"
"--middleware" "[cider.nrepl/cider-middleware]"
"-i"]}
Hint::Headless REPLλ︎
Remove the
"-i"
if a headless (non-interactive) REPL is required, useful if only interacting with Clojure code via the nREPL connected editor.
Alias to run a Rebel REPL with nREPL supportλ︎
Rebel readline provides a rich terminal UI with nrepl server , enabling CIDER to connect via cider-connect-clj
:repl/rebel
{:extra-deps {nrepl/nrepl {:mvn/version "0.9.0"}
cider/cider-nrepl {:mvn/version "0.27.4"}
com.bhauman/rebel-readline {:mvn/version "0.1.4"}}
:main-opts ["-m" "nrepl.cmdline"
"--middleware" "[cider.nrepl/cider-middleware]"
"-i"
"-f" "rebel-readline.main/-main"]}
Hint:: practicalli/clojure-deps-edn contains common tools and aliasesλ︎
practicalli/clojure-deps-edn contains aliases for all aspects of Clojure development with the CLI tools.
{% endtabs %}
Using Cider Connectλ︎
Start the REPL in a terminal including the test
directory and starting an nREPL server for CIDER to connect too.
Alternatively, use a rich terminal UI for the REPL using Rebel Readline which will also start an nREPL server for Cider to connect too.
Using CIDER jack-inλ︎
.dir-locals.el
file can define aliases which are always included during cider-jack-in
.
Add the variable cider-clojure-cli-aliases
with a names of one or more alias names, which are from either the project deps.edn
file or the user level deps.edn
configuration.
SPC p e
creates or opens an existing .dir-locals.el
file for the current project.
Remember to SPC b R
(revert-buffer
) on an existing project buffer, or open a file from the current project, to force Emacs to load in any changes to a .dir-locals.el
file.
Hint::Project configuration with
.dir-locals.el
λ︎Project level configuration section contains many example configurations that can be set via
.dir-locals.el
file. Remember torevert-buffer
an existing project buffer or open a new buffer to load in changes from the.dir-locals.el
file.
Edit the jack-in commandλ︎
SPU u , '
uses the Emacs universal argument with sesman-start
and displays the command line to be run.
Add :env/test
directly after the -M
flag and before the :cider/nrepl
alias
SPC u
is the Spacemacs equivalent ofC-u
in Emacs.
Checking the jack-in commandλ︎
SPC b m
opens the messages buffer and the full command should be shown in the messages history.