testing

Drew Verlee 2024-07-16T02:42:33.979589Z

I want to store my tests as data so i can pass them around to a couple different places. I imagine something like:

[{:fn 'foo :input [0] :output 0}
 {:fn 'foo :input [1] :output 1}]
However, most testing frameworks, notable clojure.test, likely for good reasons, use macros, so it's obvious to me how to do this. I was going to look around at some other frameworks and how they did things...

2024-07-16T14:58:15.863499Z

macros don't preclude you using variable input data. you could say

(deftest example-test
  (doseq [{:keys [f inputs output]} tests]
    (is (= output (apply f inputs)))))
and that would work just fine

Drew Verlee 2024-07-16T16:02:46.139159Z

good point

seancorfield 2024-07-16T03:10:46.824059Z

clojure.test-compatible libraries use metadata on symbols, so if you can turn your data into an anonymous fn, you can programmatically attach it as :test metadata to a var.

👀 1
Drew Verlee 2024-07-16T03:58:07.267279Z

Thanks sean. Why does it need to be an anonymous fn? Whats an example of a clojure.test-comptabible library? my googling found expectations and rfc.

seancorfield 2024-07-16T04:54:45.860849Z

Well, it doesn't need to be anonymous but it's just a function value and it's attached to the original symbol as :test metadata. Did you mean RCF rather than RFC? I wouldn't really call that clojure.test-compatible since it doesn't create statically-predictable named tests. expectations.clojure.test is clojure.test-compatible by design (the "classic" Expectations library is not, nor is Midje). Don't confuse that with test runners.