lambdaisland / kaocha

Full featured next gen Clojure test runner
https://cljdoc.org/d/lambdaisland/kaocha/1.0.861/doc/1-introduction
Eclipse Public License 1.0
796 stars 82 forks source link

Fixtures not ending in test result do not work with kaocha v1.73.1175 onwards #388

Closed Wegi closed 1 year ago

Wegi commented 1 year ago

Description:

When tests use fixtures like the following:

(defn init-execute-teardown-fixture
  [f]
  (init-db-data)
  (f)
  (clean-db))

Then kaocha tries to cast the result of the clean-db call and not the test. E.g. if it is a Boolean, you get the exception: class java.lang.Boolean cannot be cast to class clojure.lang.Associative (java.lang.Boolean is in module java.base of loader 'bootstrap'; clojure.lang.Associative is in unnamed module of loader 'app')

The fixture pattern above is the usual fixture pattern and even used in multiple examples in the official documentation.

A temporary fix is to return the test result from the fixture, like so:

(defn init-execute-teardown-fixture
  [f]
  (init-db-data)
  (let [test-result (f)]
    (clean-db)
    test-result))

I can provide more example data, but this should be easy to reproduce.

Thanks!

plexus commented 1 year ago

Can you try

[lambdaisland/kaocha "1.76.1230"]
{lambdaisland/kaocha {:mvn/version "1.76.1230"}}

please? I believe we merged a fix for this recently.

Wegi commented 1 year ago

Worked, flawlessly. Thanks for the work. 👍

NoahTheDuke commented 5 months ago

We've come across an issue related to this: If you run the test in a fixture twice and only the first instance fails, then the fail is printed but the returned result says that there are no failures.

Given:

(def ^:dynamic *val* 0)

(defn doubled-fixture [f]
  (binding [*val* 1]
    (f))
  (binding [*val* 2]
    (f)))

(use-fixtures :once doubled-fixture)

(deftest example-fail-test
  (is (= *val* 2)))

Output:

$ clojure -M:test
[(F.)]

FAIL in noahtheduke.example.repo-test/example-fail-test (repo_test.clj:16)
Expected:
  1
Actual:
  -1 +2
1 tests, 1 assertions, 0 failures.

$ echo $?
0