Clojure测试'是'断言没有执行

时间:2016-03-12 14:48:32

标签: testing clojure

我有一个程序从stdin获取输入并将其输出写入stdout。为了测试它,我使用with-in-str传递它输入,然后将 out 绑定到一个临时文件,该文件被啜饮并与预期结果进行比较。使用此方法成功写入文件。然而,当我为is断言啜饮文件时,断言没有断言,并且在打印出之后的任何打印都没有打印出来。

(def test-case
  {
   :name  "input is less than batch size"
   :input ["a" "a"]
   :batch-size 3
  })

(deftest assertion-failing
  (testing "sample code of assertion failing to execute"
    (let [rand-file (str "/tmp/fl" (rand 10000))
          want      "{\"a\": true}"]
      (mock-and-run-test test-case rand-file)
      (println "before slurp")
      (is (= (slurp rand-file) want))
      (println "after slurp"))))

执行此测试时的输出是:

bash-3.2$ lein test :only collection.core-test/assertion-failing

lein test collection.core-test
before slurp
bash-3.2$ 

EDITED
以下是mock-and-run-test及其帮助形式run-t

(defn run-t
  [tt rand-file]
  (binding [*out* (clojure.java.io/writer rand-file)]
    (with-in-str
      (str/join "\n" (:input tt))
      (-main "-c" "users-query"))))

(defn mock-and-run-test
  [tt rand-file]
  (with-redefs
    [batch-size-map {"users-query" (:batch-size tt)}
     works-check  (fn [t] true)]
    (run-t tt rand-file)))

0 个答案:

没有答案