【发布时间】:2018-09-09 22:05:26
【问题描述】:
我为我的 API 创建了 2 个“功能”测试,当我使用 lein test 一次运行所有测试时,来自一个测试的请求会在下一个测试用例中传播。
我想知道是否有办法在运行 deftest 后取消模拟或撤消请求。
我正在使用ring/ring-mock,使用ring.mock.request/mock 模拟请求,我正在使用leingein 运行测试
file1.clj
(deftest some-test
(testing ""
(app (-> (mock/request :post "/some-endpoint")
(mock/content-type "application/json")
(mock/body (cheshire/generate-string {:some "value"}))))
file2.clj
(deftest some-other-test-file
(testing ""
(let [response (app (-> (mock/request :get "/some-endpoint"))]
; response has {:some "value"}
)))
【问题讨论】:
-
是的。但由于它是一个功能测试,因此我在发布某些内容时重新定义的变量不能从我的测试文件中使用
with-redefs。 -
你能添加示例代码来显示问题吗?
-
@AlanThompson 的伪代码够清楚吗?
-
请记住,with-redef 使我们严格不适合并行运行测试。它不是线程安全的。如果您想使用它,您需要确保它已被使用,以便它包装所有将并行运行的测试。