3

对于 Clojure 新手来说,我可能遇到了最简单的测试失败,并带有一条相当令人困惑的消息。

(ns leiningen.booltest
  (:use clojure.test))

(with-test
  (defn bool-function [] 
    (true))

  (is (= (bool-function) true))
)

ERROR in (bool-function) (booltest.clj:10)
expected: (= (bool-function) true)
  actual: java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.IFn
4

1 回答 1

8

您将 true 作为函数调用:(true)with-test表达式的第 3 行。它应该是true,不带括号。

您可以进一步简化您的表达式,因为bool-function已经返回true

 (with-test
      (defn bool-function [] 
        true)
      (is (bool-function)))
于 2012-12-24T20:42:54.150 回答