Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing Clojure中的单元测试不';当我测试自己的函数时,我不会编译_Unit Testing_Clojure - Fatal编程技术网

Unit testing Clojure中的单元测试不';当我测试自己的函数时,我不会编译

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)

我是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)
  (: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
vs
demo.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
vs
demo.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")
)