Skip to content

Instantly share code, notes, and snippets.

@metametadata
Created November 3, 2017 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metametadata/c40a5f099814e591cd627b874f9bb595 to your computer and use it in GitHub Desktop.
Save metametadata/c40a5f099814e591cd627b874f9bb595 to your computer and use it in GitHub Desktop.
Prettifying Clojure test reports
; Prettify test reports
(ns unit.reporter
(:require
[clojure.test :refer [report with-test-out]]))
; Change the report multimethod to ignore namespaces that don't contain any tests.
; taken from: http://blog.jayfields.com/2010/08/clojuretest-introduction.html
(defmethod report :begin-test-ns [m]
(with-test-out
(when (some #(:test (meta %)) (vals (ns-interns (:ns m))))
(println "\n-------====== Testing" (ns-name (:ns m)) "======-------"))))
; Report test names
(defmethod report :begin-test-var [m]
(with-test-out
(println "\r\uD83C\uDF00 " (:verbose-name (meta (:var m))))))
(def ansi-reset "\u001B[0m")
(def ansi-bold "\u001B[1m")
(def ansi-red "\u001B[31m")
; Summary reporting with color
(defmethod report :summary [m]
(try
(print ansi-bold)
(when (not (every? zero? [(:fail m) (:error m)]))
(print ansi-red))
(with-test-out
(println "\nRan" (:test m) "tests containing"
(+ (:pass m) (:fail m) (:error m)) "assertions.")
(println (:fail m) "failures," (:error m) "errors."))
(finally
(print ansi-reset))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment