What is the typical way to structure integration and unit tests in Clojure?
So far I have a test/
folder that follows the structure of my src/
directory. But I would like to split these into unit tests and integration tests.
Is there a recommended strategy? Annotations in tests? sub-folders test/unit
and test/integration
? Environment variables?
Note: I use boot
instead of leiningen
in case it matters
The organization is up to you. You can either make a separate directory tree for the integration tests, have separate files in the same directory tree, or have unit tests and integration tests in the same test source files.
The only real difference between unit & integration tests is
So, either way, all of the integration tests should be labelled with ^:integration
metadata on each function. This technique is also useful with "slow" unit tests.
A "slow" test can be marked like this one (which uses clojure.test.check
generative testing):
(tst/defspec ^:slow round-trip-bytes 9999
(prop/for-all [orig gen/bytes]
(let [string-b64 (b64/encode-bytes->str orig)
result (b64/decode-str->bytes string-b64) ]
(assert (every? b64/base64-chars (seq string-b64)))
(assert (types/byte-array? result))
(= (seq orig) (seq result)))))
Then in your project.clj
(not boot, I know), specify:
:test-selectors { :default (complement :slow)
:slow :slow }
Then when you say lein test
the tests marked with ^:slow
will be skipped, and when you say lein test :all
all of the tests (including the "slow" ones) will be run.
Note that there is nothing special about the keyword :slow
. You can substitute any keyword you wish, such as :integration
.
I have not used boot
much but I assume a similar technique is available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With