0

I am new to Clojure and now I'm trying to use some unittesting.

I have a sample project with this structure:

structure of my sample project

core.clj in src/hello contains

(ns hello.core
  (:gen-class))

(defn side-eq [x]
  (if (< 0 (count x)) 
    (= (.charAt x 0) (.charAt x (- (count x) 1)))
    false))

core.clj in test/hello contains

(ns hello.core    
  (:use clojure.test)
  (:require [hello.core :refer :all])
  (:gen-class))


(use 'clojure.test)
(deftest side-eq-tests (
                         is (= false (side-eq "aws"))))

(run-tests)

when I execute tests, it throws

java.lang.RuntimeException: Unable to resolve symbol: side-eq in this context

When I test something like

is (= 1 1)

then everything works fine.

What is going on?

2 Answers 2

2

You should not have multiple files with the same namespace. Rename your tests to something else. The idiomatic name here would be hello.core-test In test/hello/core_test.clj

Sign up to request clarification or add additional context in comments.

Comments

0

A variation which I prefer is to begin all testing namespacese with the tst.* prefix, which avoids the hyphen-underscore conversion & confusion (e.g. demo.core-test vs demo.core_test.clj. So your files look like so:

> d **/*.clj
-rwxrwxr-x 1 alan alan 1024 Jan  5 19:00 project.clj*
-rwxrwxr-x 1 alan alan   84 Jan  5 15:29 src/demo/core.clj*
-rwxrwxr-x 1 alan alan  248 Jan  7 12:42 test/tst/demo/core.clj*

and the code looks like:

(ns demo.core)

(defn -main []
  (println "main - enter")
)

and

(ns tst.demo.core
  (:use demo.core tupelo.core tupelo.test)
  (:require
    [tupelo.misc :as tm] ))

....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.