unit-testing - 无法解析符号: is in this context

标签 unit-testing clojure test-is

我是Clojure的新手,并且在运行单元测试时遇到了一些麻烦。

(ns com.bluepojo.scratch
  (:require clojure.test))

(defn add-one
  ([x] (+ x 1))
  )

(is (= (add-one 3) 4))

给出:
java.lang.Exception: Unable to resolve symbol: is in this context

我想念什么?

更新:

这有效:
(clojure.test/is (= (add-one 3) 4))

我如何做到这一点,这样就不必在is之前声明clojure.test?

最佳答案

您对ns宏的使用不太正确,并且有几种方法可以修复它。我建议之一

1.将别名clojure.test缩短一些

(ns com.bluepojo.scratch
  (:require [clojure.test :as test))

(defn add-one
  ([x] (+ x 1)))

(test/is (= (add-one 3) 4))

2.使用use
(ns com.bluepojo.scratch
  (:use [clojure.test :only [is]]))

(defn add-one
  ([x] (+ x 1)))

(is (= (add-one 3) 4))

看一看this article,这在一定程度上解释了这一点

关于unit-testing - 无法解析符号: is in this context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4457321/

相关文章:

testing - 你怎么能 "parameterize"Clojure Contrib 的测试是?

c# - "Thread was being aborted."在测试中,测试在后台线程上触发委托(delegate)的代码

java - 如何为 int[] 编写 easyMock.expect

unit-testing - 数据驱动单元测试

Ruby,如何创建一个 Rack::Request 用于测试目的?

clojure - 在 clojure 函数名称中使用 - 和 *

clojure - 输入关闭括号时 VSCode 不缩进

clojure - `def` vs `declare` 用于前向声明