I would like to build a jar file containing a suite of clojure.test tests, and then use lein test to run those tests. As far as I can tell, :test-paths only supports paths to test source, not test jars.
Is there a way to accomplish this?
I would like to build a jar file containing a suite of clojure.test tests, and then use lein test to run those tests. As far as I can tell, :test-paths only supports paths to test source, not test jars.
Is there a way to accomplish this?
Copyright © 2021 Jogjafile Inc.
You can do this by manually creating a test runner. Suppose you have a project
demoand a testing nstst.demo.corelike so:Under the
src/demodirectory, create a test driverdemo.tstlike so:We can run our driver which will call all of our tests in
tst.demo.core:How It Works:
We digress a bit to discuss the Clojure
var. Thevaris like a pointer from a symbol likepito the function that prints3.14. Normally we don't even realize thevaris there, as with the first printout:We invoked the
pifunction, which returned the value 3.14, as usual.However, we can get a reference to the
varfor thepifunction using the wither#'pior(var pi). We then invoke thepifunction using the var, not the symbolpi. We see:We use the
ns-internsto get a map from symbols to vars in thetst.demo.corenamespace (note: it is critical that we have:require [tst.demo.core ...]at the top of the file in thensform). We printout this map:We only need the vars themselves, so we grab them and save into
tst-vars:Note that each
(dotest ...)form in the testing nstst.demo.corecreates a function that is invoked duringlein test. We can invoke these functions ourselves, using the vars we just retrieved. This is what thedoseqloop does, and we see the output of our mock test functionst1andt2:The final step is to designate
demo.tstas the main ns inproject.cljviawhich should allow you to create a uberjar and run it: