librelist archives

« back to archive

custom test reports

custom test reports

Dmitry Neverov
2013-08-10 @ 13:18

I'm trying to implement an on-the-fly test reporting for leiningen
running inside CI server we use (TeamCity). To do that I need to print
some lines for every test a CI server would recognize, something like
'test started' with a test name, 'test finished', 'test failed' and so

I'm trying to implement that using a hook that wraps
clojure.test/report, but without success so far.

My code goes like this:

(defn add-teamcity-reporting [f & args]
  `(binding [~'clojure.test/report
             (fn [m#]
               (println "custom output")
               ((.getRawRoot #'clojure.test/report) m#))]
     ~(apply f args)))

(defn hooks []
  (robert.hooke/add-hook #'leiningen.test/form-for-testing-namespaces

I'm testing it by building core.logic, but every time I run 'lein test'
I get the following error:

Exception in thread "main" java.lang.NullPointerException
        at clojure.core$swap_BANG_.invoke(core.clj:2161)
        at leiningen.core.injected$add_hook.invoke(NO_SOURCE_FILE:1)
        at user$eval37.invoke(NO_SOURCE_FILE:1)
        at clojure.lang.Compiler.eval(
        at clojure.lang.Compiler.eval(
        at clojure.lang.Compiler.eval(
        at clojure.core$eval.invoke(core.clj:2852)
        at clojure.main$eval_opt.invoke(main.clj:308)
        at clojure.main$initialize.invoke(main.clj:327)
        at clojure.main$null_opt.invoke(main.clj:362)
        at clojure.main$main.doInvoke(main.clj:440)
        at clojure.lang.RestFn.invoke(
        at clojure.lang.Var.invoke(
        at clojure.lang.AFn.applyToHelper(
        at clojure.lang.Var.applyTo(
        at clojure.main.main(

Does that happen because leiningen.test/form-for-testing-namespaces
re-binds clojure.test/report? What's the right way to get custom reports
without writing a separate task?