Trying to use clojure.test.check in repl, says FileNotFound, please help

Hi everyone,
I’ve been reading and learning with the book Getting Clojure by Russ Olsen.
Now I’m on a chapter about tests but when I get up to the bit where it uses clojure.test.check, I use this bit of code in my repl:
(require '[clojure.test.check.generators :as gen])

And it throws a FileNotFound exception. I am not sure what I am doing wrong, if anyone can please help me?
I am using VS Code with the Calva extension to do my Clojure learning with, I checked with the lein repl from my project root directory and the code had the same problem there too.

Here is the full exception info from Calva if that helps:
Execution error (FileNotFoundException) at inventory.core-test/eval15364 (form-init9572728795392061874.clj:1). Could not locate clojure/test/check/generators__init.class, clojure/test/check/generators.clj or clojure/test/check/generators.cljc on classpath.


I keep forgetting half the time myself, but you need to add it as a dependency (iirc)

[org.clojure/test.check "1.0.0"]

Thank you very much!
So I guess that means one can’t require it into their repl - it must be in the project.clj file? So I can’t just open a repl and play around with it? Is there a way to tell if something needs to be added as a dependency or just try to require it and see if it throws a FileNotFound exception?
Thanks again for the help and wish you a beautiful day or maybe evening wherever you are :wink:

1 Like

The best thing to figure out if something needs to be added as a dependency or is a part of the core is to read the docs. Clojure is generally well documented. I think spec’s documentation specifies that test.check is an extra dep.
To avoid having to restart your REPL every time you can use to add the dependencies dynamically, so even if you get an exception you don’t need to restart everything.
If you’re an Emacs user you can refer to this blogpost to type less when using pomegranate:

1 Like

Ah OK thank you very much for the tips - it’s been a great help! :smiley:

1 Like

As you’re using Leiningen there are two steps to enabling a library:

  • Place a reference to it in either your project’s project.clj or ~/.lein/profile.clj
  • Load it into the REPL

To load it into the REPL you can:

  1. Load it by putting a command into the project.clj / profile.clj
  2. Create a development profile and load it there
  3. Load it in your source code
  4. Load it manually

The first two options (1) and (2) are often used for development tooling. Loading the test tools is probably a good use-case for this. I’ve written a post about Lein and development workflow that might be worth checking out.

For just trying a library there’s two options:

  • Using Pomegranate (as @bsless) suggested to load the library inside the REPL.
  • Using Lein-try which is a Lein plugin that lets you “try” a library

I seem to not really use either much - I just add the library to my “scratch” project.clj - start the REPL and load it manually to play for a bit.

1 Like

Thanks for the detailed info, I skimmed through that page on your site with the Lein and dev workflow, great stuff!
Yeah, I think I’ll just not over-complicate things right now and just add the dependency to a dummy project as you say when I want to play around with something.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.