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 婆婆高寿祝福语大全简短