清除测试环境的数据数据库?
wiping out a datomic db for test environment ?
我正在尝试在测试之间截断我的数据组数据库。我在 google 上看到很多关于切除和如何删除数据的问题,但是 none 关于只是擦除数据库的问题。
我正在使用 core.test 执行以下操作:
(with-redefs [db/uri "datomic:free://localhost:4334/test_om_asyn101_next"
db/conn (d/connect db/uri)]
(run-tests 'rtest.core-test))
我一直在通过更改 URI 并重新创建来清除数据库,但我已经厌倦了这样做!谢谢!
有一个 delete-database fn. See day of datomic 教程,其中包含有关如何为每个测试创建新的内存数据库的示例。
另外,yeller has a nice example of how to use datomic's "what if" 进行单元测试的功能。
我一直按照 dAni 的建议使用 (delete-database)
,使用 clojure.test 夹具:
(ns test-util)
(defn datomic-rollback-fixture [test-fn]
;; setup
(run-migrations)
;; run the tests
(test-fn)
;; clean up
(let [datomic-uri (get-in config/config [:datomic :uri])]
(when (string/starts-with? datomic-uri "datomic:mem:")
(d/delete-database datomic-uri))))
(run-migrations)
函数从我们通过 conformity 定义的 EDN 文件加载我们的架构定义。关于只销毁 datomic:mem
数据库的一点是因为我对意外删除生产中的数据库很偏执。
然后在测试函数中,我们有:
(use-fixtures :each test-util/datomic-rollback-fixture)
(deftest my-test ...)
到目前为止,我似乎工作得很好,而且内存数据库足够快。
我正在尝试在测试之间截断我的数据组数据库。我在 google 上看到很多关于切除和如何删除数据的问题,但是 none 关于只是擦除数据库的问题。
我正在使用 core.test 执行以下操作:
(with-redefs [db/uri "datomic:free://localhost:4334/test_om_asyn101_next"
db/conn (d/connect db/uri)]
(run-tests 'rtest.core-test))
我一直在通过更改 URI 并重新创建来清除数据库,但我已经厌倦了这样做!谢谢!
有一个 delete-database fn. See day of datomic 教程,其中包含有关如何为每个测试创建新的内存数据库的示例。
另外,yeller has a nice example of how to use datomic's "what if" 进行单元测试的功能。
我一直按照 dAni 的建议使用 (delete-database)
,使用 clojure.test 夹具:
(ns test-util)
(defn datomic-rollback-fixture [test-fn]
;; setup
(run-migrations)
;; run the tests
(test-fn)
;; clean up
(let [datomic-uri (get-in config/config [:datomic :uri])]
(when (string/starts-with? datomic-uri "datomic:mem:")
(d/delete-database datomic-uri))))
(run-migrations)
函数从我们通过 conformity 定义的 EDN 文件加载我们的架构定义。关于只销毁 datomic:mem
数据库的一点是因为我对意外删除生产中的数据库很偏执。
然后在测试函数中,我们有:
(use-fixtures :each test-util/datomic-rollback-fixture)
(deftest my-test ...)
到目前为止,我似乎工作得很好,而且内存数据库足够快。