Fork me on GitHub
#test-check
<
2019-08-20
>
kenny19:08:53

Is there a good way to provide some initialization for a property when used with the clojure.test integration? For example, I have this code:

(defspec my-gen-test
  100
  (kafka/with-driver [d (make-driver {})]
    (prop/for-all [record (my-record-gen)]
      (kafka/pipe-input d record))))
It needs to initialize a Kafka test driver and then run the property test. with-driver is basically the same as with-open (i.e. it will close a resource after the form's body completes). The problem I'm running into is the property check doesn't appear to block until it's completed so the driver opens and then closes pretty quickly. Is there a way to work around this? Currently thinking to just make my own defspec that can handle this sort of thing.

kenny19:08:00

I could write my own quick-check fn like this:

(defn quick-check
  [num-tests property & opts]
  (tc-test/assert-check
    (apply tc/quick-check num-tests property opts)))

gfredericks19:08:12

@kenny you it to be opened/closed just once for the whole test run, across many trials?

kenny19:08:28

Yes. Open at the beginning, close at the end.

kenny19:08:49

It should run through all the properties using the same driver.

gfredericks19:08:43

If you did it in a fixture and bound a dynamic var, would that be good enough?

kenny19:08:22

Yes but fixtures are icky. They either run with each deftest or only once. Neither of those choices are a good fit.

gfredericks19:08:21

Yeah I don't think there are any super clean options

kenny19:08:14

That quick-check wrapper fn should work for now

👍 4