testing

Testing tools, testing philosophy & methodology...
donavan 2020-01-31T13:26:41.003300Z

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?

seancorfield 2020-01-31T17:35:51.004300Z

@donavan Not quite sure what you're asking. is creates the assertions. deftest creates the functions-with-metadata (that test runners look for).

tanzoniteblack 2020-01-31T17:44:16.007100Z

@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))

tanzoniteblack 2020-01-31T17:46:11.009Z

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

tanzoniteblack 2020-01-31T17:46:16.009200Z

but yeah, both work

tanzoniteblack 2020-01-31T17:46:22.009400Z

"work", depending on what your goal is

seancorfield 2020-01-31T18:09:57.011100Z

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.

seancorfield 2020-01-31T18:15:14.012900Z

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