testing 2024-02-16

Hi all. I'm trying to understand the cognitect-labs/test-runner. The README specifies I need to add two lines to my deps.edn:

:main-opts ["-m" "cognitect.test-runner"]
:exec-fn cognitect.test-runner.api/test}
Why would I need both? I thought -m would set the entry point of my application to be the -main function inside cognitect.test-runner. But then we also have exec-fn. Which is executed first? Why are there two entry-points?

You don't really need both. You can use :main-opts with -M:test or -M:test:runner or however you have your aliases set up. You can use :exec-fn with -X:test or -X:test:runner etc.

👍 1

It's just shorthand for showing both possible execution modes.

(some of my projects rely on -X:test:runner, some on -X:test, some do it via build.clj so it's clojure -T:build test...)

OK thanks Sean

I'm not sure this test runner is suitable for my needs since it doesn't seem to provide a way to run an initialization function (e.g. to start db connection etc)

That's what test fixtures are for.

See this example app for test fixtures that set up a database before running tests: https://github.com/seancorfield/usermanager-example/blob/develop/test/usermanager/model/user_manager_test.clj

wow amazing! that will make things much easier