Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to run tests with an alias in Clojure

I’m just getting started in Clojure, and I’m trying to figure out how to run tests using an alias. Here’s what my deps.edn file looks like:

 {:paths ["src"]
 :aliases {
           :test {:extra-paths ["test"]
                  :main-opts ["-e" "(require 'clacks/core-test) (clojure.test/run-tests 'clacks/core-test)"]}}}

Here’s what my directory structure looks like:

.
├── deps.edn
├── src
│   └── clacks
│       └── core.clj
└── test
    └── clacks
        └── core_test.clj

Here’s what my core_test.clj file looks like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(ns clacks.core-test
  (:require [clojure.test :refer [deftest is testing run-test]]
    [clacks.core :refer [alphabet]]))

(deftest alphabet-test 
  (testing "Testing the alphabet"
    (is (map? alphabet) "Not a map!")
    (is (seq alphabet))))
(run-test alphabet-test)

And finally, here’s the error I’m getting when I try to run clj -M:test

Could not locate core_test__init.class, core_test.clj or
core_test.cljc on classpath. Please check that namespaces with dashes
Blockquote
use underscores in the Clojure file name.

Any idea why this is happening? Any help would be really appreciated. Thanks!

>Solution :

Namespace segments are separated with dots, not slashes – regardless of whether it’s in some (ns ...) form or some other context, like (require ...).

So this part

(require 'clacks/core-test) (clojure.test/run-tests 'clacks/core-test)

should be

(require 'clacks.core-test) (clojure.test/run-tests 'clacks.core-test)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading