Fork me on GitHub
#cider
<
2022-05-24
>
Jared Nelsen18:05:28

I am having a problem with testing using CIDER while testing. Every time I run a test in the project I am working on I get something to the effect of:

java.io.FilenotFoundException: Could not local my_project/test__init.class, my_project/test.clj on classpath at clojure.lang.RT.load ...
Could this have something to do with the version of nrepl = 0.8.3 or cider-nrepl = 0.25.5 that I am on? I am using deps.edn and not Leiningen

jumar18:05:55

What's your test namespace and what is the filename?

Jared Nelsen18:05:58

Test namespace = test-project.test Filename = test.clj

jumar18:05:55

It says Could not local my_project/test__init.class, my_project/test.clj on classpath so it's apparently looking for my-project.test ns.

jumar18:05:25

A few more tips/questions: • double check the namespace of the test you are running • how exactly are you running the test (which cider command?) • does it work with some other tests / test namespaces? • can you share the test or even the project? if not, perhaps you can create an isolated reproducer?

practicalli-johnny20:05:37

also check that the test code is on the class path Take a look at https://practical.li/clojure/testing/unit-testing/ to see a common approach to structuring unit tests in clojure

dpsutton18:05:46

are your tests on the classpath?

Jared Nelsen18:05:14

Im not sure how to determine this. How would I do that?

dpsutton18:05:08

they appear not to be. but your tests are most likely under test directory. Common to have that path under an alias that adds them. In your deps.edn do you have a :extra-paths ["test"] or something equivalent?

Jared Nelsen18:05:32

I do have an :extra-paths ["test"] entry but I just went and looked at the test directory and the tests are actually in a subdirectory called integration . I am guessing I need to specify that somehow in the :extra-paths vector? Something like :extra-paths ["test/integratioh"] ?

👍 1
vemv20:05:43

Grep for defcustom cider-clojure-cli here as well, understanding these is important for tools.deps users https://github.com/clojure-emacs/cider/blob/master/cider.el

practicalli-johnny20:05:02

No need to read the cider code (and one of those cli values is deprecated, so shouldn't be used). The cider-jack-in command can be edited by using C-u before calling the command/key binding Or create a .dir-locals.el file and use cider-clojure-cli-aliases to define aliases to include when calling cider-jack-in https://practical.li/spacemacs/clojure-projects/project-configuration.html

vemv20:05:52

No need to read the cider code is bit of an overstatement though - defcustom declarations are documentation! Also I can't find a make-obsolete-variable for one of those variables - maybe something could be improved?

Jared Nelsen20:05:33

I've added the "`test/integration"` entry to the :extra-paths vector and there was no change. I took your advice and used C-u before cider-jack-in and saw that looks every different from my deps.edn . I am beginning to suspect I might not be following the right workflow: I am:

1. cider-jack-in
2. cider-load-all-project-ns
3. Navigating to the test file
4. C-c C-t t to run individual test
Is there something I have to do differently when I jack in in order to use the deps.edn configuration?

Jared Nelsen20:05:08

Or am I missing a step? I do that same workflow for our other projects and it seems to work fine

dpsutton20:05:21

no it uses the deps.edn to understand your project. My suggestion. ignore cider. start a repl from a command line. get to a point where you can • start the repl (`clj -A:<whatever-aliases-you-need`) • require the test namespace (`(require 'my.namespace-test)`) • get in the test namespace (`(in-ns 'my-namespace-test)`) • run the tests there (`(clojure.test/run-tests)`) Once you can achieve all of these, you will understand what CIDER needs in order to run the tests. And if any of these steps fail, you know that CIDER would fail similarly.

dpsutton21:05:12

once this works • start up CIDER. Did you need to add any aliases to ensure your test namespaces were on the classpath? You’ll need to add them for CIDER • then just go to the test namespace you are interested in and require it • try running ns tests at this point

Jared Nelsen21:05:39

I got things to work in Calva but still no luck with Emacs. I will revisit this with Emacs when I have time. The same problem was happening with Calva until I used the right click and Load Current File and Dependencies. After I did that the tests worked fine. Is there an analog to this in Emacs that I can try?

dpsutton21:05:19

cider-load-file

Jared Nelsen21:05:16

Still nothing. I am just going to go with Calva for now but will revisit this. Thanks all for the help!