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 生日广州男生祝福语简短