README.adoc

January 11, 2024 · View on GitHub

= Kaocha plugin kaocha-test-ns-hook :sectnums:

== How to install

To include this plugin for Kaocha in your project, simply add the following to your project.clj dependencies:

[listing]

[org.clojars.philoskim/kaocha-test-ns-hook "0.3.0"]

== Use example

=== project.clj for lein

[listing]

(defproject my-project "0.1.0" :dependencies [[org.clojure/clojure "1.11.1"] [lambdaisland/kaocha "1.87.1366"] [org.clojars.philoskim/kaocha-test-ns-hook "0.3.0"]] :aliases {"unit-test" ["run" "-m" "kaocha.runner" ":unit"]})

=== tests.edn for Kaocha

[listing]

{:kaocha/tests [{:kaocha.testable/type :kaocha.type/clojure.test, :kaocha.testable/id :unit, :kaocha/ns-patterns ["-test$"], :kaocha/source-paths ["src"], :kaocha/test-paths ["test"], :kaocha.filter/skip-meta [:kaocha/skip]}] :kaocha/fail-fast? false, :kaocha/color? true, :kaocha/cli-options {:config-file "tests.edn", :print-config true}, :kaocha.plugin.randomize/randomize? false, :kaocha/plugins [:kaocha.plugin/filter :philoskim.kaocha/test-ns-hook], ; <-- here :kaocha.plugin.capture-output/capture-output? false, :kaocha/reporter [kaocha.report/dots]}

=== a test sample

[listing]

;; test/my_test.clj (ns my-test (:require [clojure.test :refer :all]))

(deftest test-a (testing "test-a" (is (= 1 1)) (is (= (+ 2 2) 5)) ))

(deftest test-b (testing "test-b" (is (= 10 10)) (is (= 20 20))))

(defn test-ns-hook [] (test-a) (test-b))

=== Running Kaocha

[listing]

$ lein unit-test [(.F..)]

FAIL in my-test/test-ns-hook (my_test.clj:8) test-a Expected: 4 Actual: -4 +5 1 tests, 4 assertions, 1 failures.

== Limitations

  • This plugin is not perfect but I think it is better than nothing. You can use it tentatively, until the Kaocha team implements this feature.

  • This plugin has the following limitations in printed outputs but I think this limitations are not what I can cover but the Kaocha team has to solve.

** When :fail-fast? false and :kaocha/reporter [kaocha.report/dots] + what I expected is + [listing]

$ lein unit-test [(.F)(..)] ; <-- Here

FAIL in my-test/test-a (my_test.clj:8) ; <-- Here test-a Expected: 5 Actual: -5 +4 1 tests, 4 assertions, 1 failures.

but the reality is + [listing]

$ lein unit-test [(.F..)] ; <-- Here

FAIL in my-test/test-ns-hook (my_test.clj:8) ; <-- Here test-a Expected: 5 Actual: -5 +4 1 tests, 4 assertions, 1 failures.

** When :kaocha/reporter [kaocha.report/documentation] + what I expected is + [listing]

$ lein unit-test --- unit (clojure.test) --------------------------- my-test test-ns-hook test-a ; <-- Here test-a FAIL ; test-b ; test-b ;

FAIL in my-test/test-a (my_test.clj:8) ; <-- Here test-a Expected: 5 Actual: -5 +4 1 tests, 4 assertions, 1 failures.

but the reality is + [listing]

$ lein unit-test --- unit (clojure.test) --------------------------- my-test test-ns-hook test-a ; <-- Here, not indented test-a FAIL ; test-b ; test-b ;

FAIL in my-test/test-ns-hook (my_test.clj:8) ; <-- Here test-a Expected: 5 Actual: -5 +4 1 tests, 4 assertions, 1 failures.

** When :kaocha/reporter [kaocha.report.progress/report] + what I expected is + [listing]

$ lein unit-test unit: 100% [======================================================] 2/2 ; <-- Here

FAIL in my-test/test-a (my_test.clj:8) test-a Expected: 5 Actual: -5 +4 1 tests, 4 assertions, 1 failures.

but the reality is + [listing]

$ lein unit-test unit: 300% [====================================================== ; <-- Here unit: 300% [======================================================] 3/1 ; <-- Here

FAIL in my-test/test-ns-hook (my_test.clj:8) ; <-- Here test-a Expected: 5 Actual: -5 +4 1 tests, 4 assertions, 1 failures.

== License

Copyright © 2024 Young Tae Kim

Distributed under the Eclipse Public License either version 1.0 or any later version.