testing

Testing tools, testing philosophy & methodology...
2018-04-05T08:41:02.000422Z

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.

2018-04-05T08:41:24.000408Z

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.stylianos 2018-04-05T09:44:22.000383Z

@lucasvalenteds 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

2018-04-05T10:34:13.000277Z

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

2018-04-05T10:34:46.000305Z

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

andre.stylianos 2018-04-05T12:23:04.000252Z

@lucasvalenteds 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  
)

💯 1
andre.stylianos 2018-04-05T12:23:38.000063Z

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

andre.stylianos 2018-04-05T12:24:36.000289Z

Just ping me if you need more info

2018-04-05T18:33:24.000010Z

@andre.stylianos 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.

andre.stylianos 2018-04-05T18:53:07.000711Z

Glad to help!