testing

Joseph Graham 2024-02-16T05:03:38.218699Z

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?

seancorfield 2024-02-16T05:41:17.424529Z

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
seancorfield 2024-02-16T05:41:32.468689Z

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

seancorfield 2024-02-16T05:42:08.548579Z

(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...)

Joseph Graham 2024-02-17T03:20:23.927379Z

OK thanks Sean

Joseph Graham 2024-02-17T05:35:37.965779Z

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)

seancorfield 2024-02-17T06:30:49.263389Z

That's what test fixtures are for.

seancorfield 2024-02-17T06:31:22.356589Z

See https://clojuredocs.org/clojure.test/use-fixtures

seancorfield 2024-02-17T06:32:25.119229Z

See https://stackoverflow.com/questions/16350504/clojure-how-to-use-fixtures-in-testing if the docs aren't obvious.

seancorfield 2024-02-17T06:35:29.640769Z

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

Joseph Graham 2024-02-17T07:51:38.456969Z

wow amazing! that will make things much easier