我是 clojure 新手,下面是我的代码
(ns my.class.package
(:require [clojure.tools.logging :as log]
[schema.core :as s]))
(s/defn my-method :- CandidateInfo [candidates :- [CandidateInfo] goal :- Goal]
(doseq [candiate candidates]
(s/validate CandidateInfo candidate))
(s/validate Goal goal)
......)
我进行的单元测试是
(testing "test bad input schema"
(let [candidates [{:bad-attr1 "123" :bad-attr2 "456"}]
goal {:id "123" }]
(is (thrown? ExceptionInfo
(try
(my-class/my-method candidates goal)
(catch ExceptionInfo e
(throw e)))))))
我得到的错误是
ERROR in (test-my-method) (core.clj:155)
Uncaught exception, not in assertion.
expected: nil
actual: clojure.lang.ExceptionInfo: Value does not match schema: {:id missing-required-key, :name missing-required-key}
at schema.core$validator$fn__14239.invoke (core.clj:155)
schema.core$validate.invokeStatic (core.clj:164)
schema.core$validate.invoke (core.clj:159)
my.class.package.my-class$eval32123$my_method__32128$fn__32129.invoke (my-class.clj:36)
......
我的理解是,我确实期望在单元测试中抛出 ExceptionInfo。然而,错误一直说我期望为零。请帮忙!!
尝试:
(require '[schema.test :as st])
(st/deftest SchemaTest
(testing "test bad input schema"
(let [candidates [{:bad-attr1 "123" :bad-attr2 "456"}]
goal {:id "123"}]
(is (thrown? ExceptionInfo
(try
(my-class/my-method candidates goal)
(catch ExceptionInfo e
(throw e))))))))