clojure.test/deftest
creates vars that that can be invoked in order to compose tests. Is there any benefit in composing tests in this way over just using is
and the like inside a function that is called from a deftest
?
@donavan Not quite sure what you're asking. is
creates the assertions. deftest
creates the functions-with-metadata (that test runners look for).
@donavan, you mean something like:
(deftest test-1 (is (= 3 5)))
(deftest test-2 (test-1))
instead of:
(defn test-1 [] (is (= 3 5)))
(deftest test-2 (test-1))
In the first case, you're probably going to end up running test-1
twice, presuming that you're doing whole test suite runs, and the composition isn't as powerful as the functions because it only returns nil
, vs. actually being able to chain together results from the function call
but yeah, both work
"work", depending on what your goal is
Composing tests (the first case above) can be useful in those cases where two tests need to be executed in strict sequence (although having tests that depend on the order they are executed in is a bad idea in general) and when you start using test metadata to allow your test runner to run specific subsets of tests.
(I'll be honest and say that in nearly ten years of doing Clojure, I don't think I've ever seen tests composed like that tho'...)