Using Cider in Spacemacs, I can't seem to find a way to run tests that are defined in the attribute map of defn. Take this function definition for example:
(defn contains-duplicates-a?
"checks if a vector of strings contain duplicates"
{:test #(do
(is (contains-duplicates-a? ["aa" "aa"]))
(is (not (contains-duplicates-a? ["aa" "aaa"])))
(is (not(contains-duplicates-a? ["ba" "ab"])))
(is (not (contains-duplicates-a? ["abcde" "xyz" "ecdab"]))))}
[word-vector]
(not(=
(count word-vector)
(count (distinct word-vector)))))
This style of writing unit tests is fairly common at my company and it's supported by our most common IDE setup (IntelliJ + Cursive). We like having the unit tests close to the code.
I'm not sure it can be achieved by using cider-test-defining-forms
, as whatever you add there has to be a 'top level form' (doc).
Am i missing something, or is it simply not supported?
If you want to call
cider-test-run-test
on a defn like this, just adddefn
tocider-test-defining-forms
.You can also run all tests that are defined in the current namespace (including tests defined the way you've done here) in CIDER by running
cider-test-run-ns-tests
with a prefix argument. In the current stable CIDER that means you can typeC-u C-c C-t n
orC-u C-c , n
. The prefix argument (C-u) is neccessary to prevent CIDER from trying to find the tests in the typical "${current.namespace}-test" namespace.