When developing code, it is sometimes effective to focus on a single failing test, rather than running all tests in a namespace. This can be the case when running the tests takes some amount of time, or when running the tests produces a large volume of failures. The best option for running a single test with fixtures currently is `test-vars` ala:
(use 'clojure.test)
(def counter (atom 0))
(defn setup [f] (swap! counter inc) (f)) ;; a :once fixture with state
(use-fixtures :once setup)
(deftest ex (println "counter =" @counter))
(test-vars [#'ex]) ;=> counter = 1
(test-vars [#'ex]) ;=> counter = 2
However, this has the following issues:
- No test reporting feedback such as you get with run-tests (on success, there is no output)
- Need to specify var (not symbols) wrapped in a vector
*Proposed:* A new macro `run-test` that specifies a single symbol and does the same test reporting you get with `run-tests`. Usage:
(use 'clojure.test)
(def counter (atom 0))
(defn setup [f] (swap! counter inc) (f)) ;; a :once fixture with state
(use-fixtures :once setup)
(deftest ex (println "counter =" @counter))
(run-test ex)
;=> Testing user
;=> counter = 1
;=> Ran 1 tests containing 0 assertions.
;=> 0 failures, 0 errors.
;=> {:test 1, :pass 0, :fail 0, :error 0, :type :summary}
(run-test ex)
;=> Testing user
;=> counter = 2
;=> Ran 1 tests containing 0 assertions.
;=> 0 failures, 0 errors.
;=> {:test 1, :pass 0, :fail 0, :error 0, :type :summary}
*Patch:* CLJ-1908-3.patch
*Screened:* Alex Miller