If you don't mind not running fixtures, you could do the following before you call run-tests
:
(defn test-ns-hook []
(my-test))
To remove the hook, you can do
(ns-unmap *ns* 'test-ns-hook)
If you still need your fixtures and want to stay with one test namespace, you could add an ns-unmap
to remove all the tests/fixtures you don't want to run from the namespace before running your tests modelled on something like:
(doseq [v (keys (ns-publics 'my-ns))]
(let [vs (str v)]
(if (.startsWith vs "test-") (ns-unmap 'my-ns v))))
It might be easier to work with multiple namespaces, one of which contains all your tests and fixtures and in other namespace(s) refer
to the tests and fixtures you want to run from you main test namespace. You could then use ns
to switch to a specific test namespace or pass run-tests
the namespace(s) you want to test:
(ns test-main
(:require [clojure.test :refer :all]))
(deftest addition
(is (= 4 (+ 2 2)))
(is (= 7 (+ 3 4))))
(deftest subtraction
(is (= 1 (- 4 3)))
(is (= 3 (- 7 4))))
(run-tests)
;Runs all the tests
(ns test-specific
(:require [clojure.test :refer :all]
[test-main :refer :all]))
(deftest arithmetic
(subtraction))
(run-tests)
;Just runs the tests you want