lazytest

p-himik 2026-04-20T20:35:06.727189Z

Dunno if there's prior art, but I couldn't find any config options that would do it so I made a reporter that prints out the duration of each test case:

(def starts (atom {}))

(defmulti nested-with-time* lazytest.reporters/reporter-dispatch)

(defmethod nested-with-time* :default [config m]
  (lazytest.reporters/nested* config m))

(defn print-test-result-with-time [config {:keys [source] :as result}]
  (let [end (System/currentTimeMillis)
        dur (- end (@starts (dissoc source :type)))
        orig-result (with-out-str (lazytest.reporters/print-test-result config result))
        has-newline? (str/ends-with? orig-result "\n")
        new-result (str (cond-> orig-result has-newline? (subs 0 (dec (count orig-result))))
                        " (" dur " ms)")
        p (if has-newline? println print)]
    (p new-result)))

(defmethod nested-with-time* :begin-test-case [config tc]
  (swap! starts assoc (dissoc tc :type) (System/currentTimeMillis))
  (lazytest.reporters/nested* config tc))

(defmethod nested-with-time* :pass [config result]
  (print-test-result-with-time config result))

(defmethod nested-with-time* :fail [config result]
  (print-test-result-with-time config result))

(def reporter (->> lazytest.reporters/nested
                   (mapv #({lazytest.reporters/nested* nested-with-time*} % %))))

👀 1
🎉 1
2026-04-20T20:35:55.318489Z

nice!

2026-04-20T20:52:20.655039Z

i added a hook in the latest release to do generalized profiling, but i don't think i'm printing the test cases individually

p-himik 2026-04-20T20:53:14.071489Z

Yeah, I also enabled it in my tests. :) Sometimes namespace- and var-based timing is just not granular enough.

👍 1