clojure 用夹具将每个测试或所有测试包装起来
示例
use-fixtures允许deftest使用在测试之前和之后运行的代码将每个包装在命名空间中。它可以用于固定或存根。
夹具只是接受测试功能并以其他必要步骤(包装之前/之后)运行的功能。
(ns myapp.test
(require [clojure.test :refer :all])
(defn stub-current-thing [body]
;; with-redefs stubs things/current-thing function to return fixed
;; value for duration of each test
(with-redefs [things/current-thing (fn [] {:foo :bar})]
;; run test body
(body)))
(use-fixtures :each stub-current-thing)与配合使用时:once,它将带有功能的整个测试过程包装在当前名称空间中
(defn database-for-tests [all-tests] (setup-database) (all-tests) (drop-database)) (use-fixtures :once database-for-tests)
热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话