Fork me on GitHub
#leiningen
<
2022-01-03
>
zendevil.eth19:01:19

is there a way to impose order on the test namespaces that are run with lein test?

andy.fingerhut21:01:41

Not that I am aware of. I think people using clojure.test typically make any ordering constraints on order of steps, e.g. setup, do-thing1, do-thing2, do-thing3, teardown, all within a single test, never between differently named tests.

andy.fingerhut21:01:55

clojure.test does have a mechanism to call a function before each test is run, and/or when a test is finished.

zendevil.eth20:01:03

also is there a way to run a specific function before all tests are run, not before the tests in the namespace?

mikerod02:01:45

You can look into test ns hooks.

mikerod02:01:56

Which is actually a feature of clojure.test I believe.

zendevil.eth10:01:31

How to use test-ns with lein test?

zendevil.eth10:01:58

Lein test simply runs all tests in all namespaces recursively in the given directory

zendevil.eth15:01:20

note that I mean run a function before all tests are run in all ns with lein test

andy.fingerhut16:01:25

Did you see my replies to your previous message? There is a link to an example of how to do that if you are using clojure.test

zendevil.eth16:01:07

Let’s say I create this:

(defmethod test/migrations :begin-test-var [m]
    (user/start)
    (user/reset-db))
Where do I put this in my lein project and how to call it before lein test?

zendevil.eth16:01:20

I’m not making myself clear

zendevil.eth16:01:14

I mean this: 1. run fn-1 and fn-2 2. Run all tests in all namespaces NOT 1. Run fn-1 Run fn-2 2. Run test 1 3. Run fn-1 Run fn-2 4. Run test 2 …

andy.fingerhut16:01:29

I do not know of a way built into clojure.test to do that

andy.fingerhut16:01:48

except to change how you structure your tests in your namespaces, so there is only one deftest

andy.fingerhut16:01:32

but I'm not necessarily the most expert on clojure.test capabilities, either.