1

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?

Morgan
  • 325
  • 3
  • 8

1 Answers1

1

If you want to call cider-test-run-test on a defn like this, just add defn to cider-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 type C-u C-c C-t n or C-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.

Joost Diepenmaat
  • 17,633
  • 3
  • 44
  • 53
  • Ah I see, thanks! I played around with it a little and it works exactly like you said in emacs input mode in spacemacs. In vim input mode it seems that adding SPC - u (universal argument) before running `cider-test-run-ns-tests` (with SPC - m, t, n) doesn't work the same way, but that's a spacemacs issue i guess. The best way i found is to do SPC - u, SPC SPC, and type `cider-test-run-ns-tests`. The next time i type SPC - U, SPC SPC it will be suggested and i can just hit enter. And for the record, `cider-test-defining-forms` is under ~/.emacs.d/elpa/cider-20180917.1746/cider-test.el – Morgan Oct 03 '18 at 19:08