Fork me on GitHub
#testing
<
2018-04-05
>
Lucas08:04:02

Is there a test reporter for Clojure that shows the passing tests? I've used Eftest and it's awesome, but it does not show the tests title just the percentage of success.

Lucas08:04:24

Here's an example using Lein and Eftest: Test suite:

clojure
(ns language.collections
  (:require [clojure.core :refer :all]
            [clojure.test :refer :all]))

(deftest collections-test
  (testing "Commas are optional when declaring elements")
    (is (= 5 (count '(1 2 3 4 5))))
    (is (= 5 (count '(1, 2, 3, 4, 5)))))

(deftest list-test
  (testing "A List can defined by apostrophe and parenthesis")
    (is (= 3 (count '(1 2 3)))))
Current report:
text
2/2   100% [==================================================]  ETA: 00:00

Ran 2 tests in 0,015 seconds
3 assertions, 0 failures, 0 errors.
Desired report:
text
COLLECTIONS-TEST

Test "Commas are optional when declaring elements" PASSED

LIST-TEST

Test "A List can defined by apostrophe and parenthesis" PASSED

2/2   100% [==================================================]  ETA: 00:00

Ran 2 tests in 0,017 seconds
3 assertions, 0 failures, 0 errors.

andre.stylianos09:04:22

@U7AGDD81Y Test reporting uses a multimethod to handle the different cases, you can override the one for :pass probably. https://github.com/weavejester/eftest/blob/master/eftest/src/eftest/report/pretty.clj#L102

Lucas10:04:13

Thank you, @U485ZRA58. Could you point some documentation on how to do that? This is my first contact with Clojure.

Lucas10:04:46

Does the function needs to be defined in the project.clj file?

andre.stylianos12:04:04

@U7AGDD81Y as a basic setup, in the file where you call run-tests you should be able to do something like: - Require eftest.report.pretty :as pretty or something like that. - Create a defmethod like

(defmethod pretty/report :pass [m]
;; do your custom reporting code here, m should have the info you need  
)

💯 4
andre.stylianos12:04:38

define the multimethod implementation before calling run-tests and it should work

andre.stylianos12:04:36

Just ping me if you need more info

Lucas18:04:24

@U485ZRA58 Thank you for the clarification! The steps you've described makes the test cases accessible.

(ns language.collections
  (:require [clojure.core :refer :all]
            [clojure.test :refer :all]
            [eftest.report.pretty :as pretty]))

(defmethod pretty/report :pass [m]
  (println m
  ;(println (keys m) ;(:type :expected :actual :message)
  ;(println (get m :actual) ;(#object[clojure.core$_EQ_ 0x405e5bb9 clojure.core$_EQ_@405e5bb9] 5 5)
  ;(println (nth (get m :actual) 0) ;#object[clojure.core$_EQ_ 0x16f98e0 clojure.core$_EQ_@16f98e0]
  ; (println ((first (get m :actual)) true true) ;#object[clojure.core$_EQ_ 0x16f98e0 clojure.core$_EQ_@16f98e0]
))


(deftest collections-test
  (testing "Commas are optional when declaring elements")
    (is (= 5 (count '(1 2 3 4 5))))
    (is (= 5 (count '(1, 2, 3, 4, 5)))))

(deftest list-test
  (testing "A List can defined by apostrophe and parenthesis")
    (is (= 3 (count '(1 2 3)))))
0/2     0% [                                                  ]  ETA: --:--{:type :pass, :expected (= 3 (count (quote (1 2 3)))), :actual (#object[clojure.core$_EQ_ 0x64c46b16 clojure.core$_EQ_@64c46b16] 3 3), :message nil}
1/2    50% [=========================                         ]  ETA: 00:00{:type :pass, :expected (= 5 (count (quote (1 2 3 4 5)))), :actual (#object[clojure.core$_EQ_ 0x64c46b16 clojure.core$_EQ_@64c46b16] 5 5), :message nil}
1/2    50% [=========================                         ]  ETA: 00:00{:type :pass, :expected (= 5 (count (quote (1 2 3 4 5)))), :actual (#object[clojure.core$_EQ_ 0x64c46b16 clojure.core$_EQ_@64c46b16] 5 5), :message nil}
2/2   100% [==================================================]  ETA: 00:00

Ran 2 tests in 0,027 seconds
0 assertions, 0 failures, 0 errors.