Clojure: How To use-fixtures in Testing -


i writing unit tests interact database. reason useful have setup , teardown method in unit test create , drop table. there no docs :o on use-fixtures method.

here need do:

 (setup-tests)  (run-tests)  (teardown-tests) 

i not interested in running setup , teardown before , after each test, once before group of tests , once after. how do this?

you can't use use-fixtures provide setup , teardown code freely defined groups of tests, can use :once provide setup , teardown code each namespace:

;; my/test/config.clj (ns my.test.config)  (defn wrap-setup   [f]   (println "wrapping setup")   ;; note want run teardown-tests in try ...   ;; construct, example   (setup-test)   (f)   (teardown-test))       ;; my/package_test.clj (ns my.package-test   (:use clojure.test         my.test.config))  (use-fixtures :once wrap-setup) ; wrap-setup around whole namespace of tests.                                  ; use :each wrap around each individual test                                  ; in package.  (testing ... ) 

this approach forces coupling between setup , teardown code , packages tests in, that's not huge problem. can own manual wrapping in testing sections, see example the bottom half of blog post.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -