You're viewing version 1.2.0 of use-fixtures. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

use-fixtures

clojure.test

Wrap test runs in a fixture function to perform setup and
teardown. Using a fixture-type of :each wraps every test
individually, while:once wraps the whole run in a single function.

2 Examples top

  • ; See https://clojure.github.io/clojure/clojure.test-api.html for details
    
    ; my-test-fixture will be passed a fn that will call all your tests 
    ; (e.g. test-using-db).  Here you perform any required setup 
    ; (e.g. create-db), then call the passed function f, then perform 
    ; any required teardown (e.g. destroy-db).
    (defn my-test-fixture [f]
            (create-db)
            (f)
            (destroy-db))
    
    ; Here we register my-test-fixture to be called once, wrapping ALL tests 
    ; in the namespace
    (use-fixtures :once my-test-fixture)
     
    ; This is a regular test function, which is to be wrapped using my-test-fixture
    (deftest test-using-db
      (is ... 
    ))
  • ; This fixture is intended to perform setup/teardown for each individual test in the namespace. Note that it assumes the :once fixture will handle creating/destroying the DB, while we only create/drop tables within the DB.
    (defn another-fixture [f]
            (create-db-table)
            (f)
            (drop-db-table))
    
    ; Here we register another-fixture to wrap each test in the namespace
    (use-fixtures :each another-fixture)
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/test.clj:641 top

(defmulti use-fixtures
  "Wrap test runs in a fixture function to perform setup and
  teardown. Using a fixture-type of :each wraps every test
  individually, while:once wraps the whole run in a single function."
  {:added "1.1"}
  (fn [fixture-type & args] fixture-type))
Vars in clojure.test/use-fixtures: defmulti fn
Used in 0 other vars

Comments top

No comments for use-fixtures. Log in to add a comment.