[org.clojars.philoskim/kaocha-test-ns-hook "0.3.0"]
kaocha-test-ns-hook
This plugin kaocha-test-ns-hook
for Kaocha
mimics the test-ns-hook
feature in
clojure.test.
Refer to the related discussion.
So the behaviors of this plugin are exactly the same as those of clojure.test.
If test-ns-hook
function is defined in a test file, all the other deftest
s are
ignored and only test-ns-hook
function is called. So the functions defined by
deftest
s can be called orderly inside the test-ns-hook
function. (Read the
RUNNING TESTS
section in
clojure.test.)
If test-ns-hook
function is defined in a test file, all the fixtures are
not called so not run automatically. You have to call the fixture functions directly
inside the test-ns-hook
function. (Read the FIXTURES
section in
clojure.test.)
To include this plugin for Kaocha in your project, simply add the following to your
project.clj
dependencies:
[org.clojars.philoskim/kaocha-test-ns-hook "0.3.0"]
(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"]})
{: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]}
;; 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))
$ 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.
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
$ 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
$ 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
$ 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
$ 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
$ 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
$ 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.
Copyright © 2024 Young Tae Kim
Distributed under the Eclipse Public License either version 1.0 or any later version.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close