Unit testing Clojure中的单元测试不';当我测试自己的函数时,我不会编译
我是Clojure的新手,现在我正在尝试使用一些单元测试 我有一个具有此结构的示例项目: src/hello中的core.clj包含Unit testing Clojure中的单元测试不';当我测试自己的函数时,我不会编译,unit-testing,clojure,Unit Testing,Clojure,我是Clojure的新手,现在我正在尝试使用一些单元测试 我有一个具有此结构的示例项目: src/hello中的core.clj包含 (ns hello.core (:gen-class)) (defn side-eq [x] (if (< 0 (count x)) (= (.charAt x 0) (.charAt x (- (count x) 1))) false)) (ns hello.core (:use clojure.test)
(ns hello.core
(:gen-class))
(defn side-eq [x]
(if (< 0 (count x))
(= (.charAt x 0) (.charAt x (- (count x) 1)))
false))
(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)
当我执行测试时,它抛出
java.lang.RuntimeException:无法解析此上下文中的symbol:side eq
当我测试类似的东西时
is (= 1 1)
然后一切正常
发生了什么事?您不应该有多个具有相同名称空间的文件。将您的测试重命名为其他测试。这里的惯用名称是
test/hello/core\u test.clj中的hello.core test
,您不应该有多个具有相同名称空间的文件。将您的测试重命名为其他测试。这里的惯用名称是test/hello/core\u test.clj中的hello.core test
我更喜欢的一种变体是以tst.
前缀开始所有测试名称空间,这避免了连字符下划线转换和混淆(例如,demo.core test
vsdemo.core\u test.clj
。因此,您的文件看起来如下所示:
> 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*
代码如下所示:
(ns demo.core)
(defn -main []
(println "main - enter")
)
及
我喜欢的一种变体是在所有测试名称空间开始时使用tst.*
前缀,这避免了连字符下划线转换和混淆(例如demo.core test
vsdemo.core\u test.clj
)
> 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*
代码如下所示:
(ns demo.core)
(defn -main []
(println "main - enter")
)
及