How to perform integration testing in Clojure?

What are the methods and libraries for testing integration in Clojure. In particular, interaction with databases, ring applications, core.async channels, all that causes a side effect.

+4
source share
1 answer

You can use ring-mock for ring applications. An example of creating a handler layout and its use:

(let [h (-> (POST "/some/url" [] some-resource)
            (wrap-defaults api-defaults))]
  (let [resp (h (-> (request :post "/some/url")
                    (header "content-type" "application/json")
                    (body (generate-string {:foo :bar}))))]
    (is (= 303 (:status resp)))
    (is (= "" (:body resp)))
    (is (= "http://some/place/foo" (get-in resp [:headers "Location"])))))

d/b with-redefs, , . , , , , .

(testing "some d/b work"
  (let [insert-data (ref {})]
    (with-redefs
      [d/insert-data<! 
       (fn [db data] (dosync (alter insert-data assoc :db db)
                             (alter insert-data assoc :data data)))]
      (let [d (your-fn your-args)]
        (is (= {:some :expected-result} d))
        (is (= {:db {:some :connection-data} :data {:some :expected-data}} @insert-data))))))

, refs, , , .

, , clojure.test, test.check. Midje , , clojure.test , . , cljs, .

core.async, .

+6

Source: https://habr.com/ru/post/1616336/


All Articles