如何检查在 clojure with_redefs 中使用给定参数至少调用一次模拟函数?
how to check the mocked function is called atleast once with given arguments in clojure with_redefs?
如果不调用 test-service/process
,我在下面编写的测试不会失败。而且它也不检查 URL 和参数是否正确。
(deftest main-func-test
(let [event {:a 123}]
(with-redefs
[test-service/process (fn [url params] response)]
(is (= :success (main/main-func event)))))
在ruby中很简单
expect(test_service).to receive(:process).with(url, params).and_return(response)
如何检查 test-service/process
在 Clojure 中是否至少使用两个参数 URL 和 params 调用了一次?
您可以在模拟函数中捕获参数:
(deftest main-func-test
(let [event {:a 123}
args (atom nil)]
(with-redefs
[test-service/process (fn [url params]
(reset! args [url params])
response)]
(is (= :success (main/main-func event)))
(is (= [expected-url expected-params] @args)))
如果不调用 test-service/process
,我在下面编写的测试不会失败。而且它也不检查 URL 和参数是否正确。
(deftest main-func-test
(let [event {:a 123}]
(with-redefs
[test-service/process (fn [url params] response)]
(is (= :success (main/main-func event)))))
在ruby中很简单
expect(test_service).to receive(:process).with(url, params).and_return(response)
如何检查 test-service/process
在 Clojure 中是否至少使用两个参数 URL 和 params 调用了一次?
您可以在模拟函数中捕获参数:
(deftest main-func-test
(let [event {:a 123}
args (atom nil)]
(with-redefs
[test-service/process (fn [url params]
(reset! args [url params])
response)]
(is (= :success (main/main-func event)))
(is (= [expected-url expected-params] @args)))