Skip to content

A Kaocha plugin for the test-ns-hook feature in clojure.test

Notifications You must be signed in to change notification settings

philoskim/kaocha-test-ns-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kaocha plugin kaocha-test-ns-hook

  • This plugin kaocha-test-ns-hook for Kaocha mimics the test-ns-hook feature in clojure.test.

  • 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 deftests are ignored and only test-ns-hook function is called. So the functions defined by deftests 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.)

1. How to install

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"]

2. Use example

2.1. project.clj for lein

(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"]})

2.2. tests.edn for Kaocha

{: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]}

2.3. a test sample

;; 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))

2.4. Running Kaocha

$ 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.

3. 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

      $ 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.

4. License

Copyright © 2024 Young Tae Kim

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

About

A Kaocha plugin for the test-ns-hook feature in clojure.test

Resources

Stars

Watchers

Forks

Packages

No packages published