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
792 stars 81 forks source link

[enhancement] global fixtures #409

Open sirmspencer opened 1 year ago

sirmspencer commented 1 year ago

Here is a good write up of the problem https://stackoverflow.com/questions/43585325/clojure-test-global-fixtures.

TLDR is that things like connecting to a DB are slow and we don't want to do it for every namespace.

An alternative tool, circleci.test has added support for this. https://github.com/circleci/circleci.test#global-fixtures

Is there any plan to add something like this for koacha?

plexus commented 1 year ago

Use the hooks plugin, this is the kind of thing it's there for.

alysbrooks commented 1 year ago

I think we can convert this to a documentation issue—we've decided against adding global hooks, here's how we suggest using hooks in place of global fixtures, here's an example, etc.

In theory, you wouldn't need to use hooks at all, you could have a test namespace that declares a var with delay.


(def test-db (delay (let [db-params {:connection-uri "sqlite:////memory"}]
                               ;steps to set up database      
db-params)))

;In a test namespace:
(deftest some-db-test
   (testing insert-something 
           (jdbc/insert! @test-db ,,,)))
alysbrooks commented 1 year ago

It might also be good to document this pattern in conjunction with our forthcoming parallel execution support. If namespaces are creating things that should only be accessed by one thread at a time, it could cause issues.