There are two directories in a clojure project – src/ and test/.
There’s a file my_methods.clj in the src/calc/ directory which starts with
(ns calc.my_methods...).
I want to create a test file for it in test directory – test/my_methods-test.clj
(ns test.my_methods-test
(:require [calc.my_methods])
(:use clojure.test))
In the $CLASSPATH there are both project root directory and src/ directory. But the exception is still
“Could not locate calc/my_methods__init.class or calc/my_methods.clj on classpath”. What is the problem with requiring it in the test file?
echo $CLASSPATH gives this:
~/project:~/project/src
First, I’d suggest using Leiningen to manage the
CLASSPATHfor you. Second, I find that the~character to stand in for my home directory never works in theCLASSPATHcontext – I have to specify the absolute path, no aliasing (e.g./Users/colin/path/to/project). Third, it’s conventional to havesrcandteston the classpath, but not the root level of a project.