test-check

kenny 2019-08-20T19:27:53.006300Z

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.

kenny 2019-08-20T19:32:00.006700Z

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

2019-08-20T19:34:12.007600Z

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

kenny 2019-08-20T19:34:28.007900Z

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

kenny 2019-08-20T19:34:49.008400Z

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

2019-08-20T19:35:43.009Z

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

kenny 2019-08-20T19:36:22.009800Z

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

2019-08-20T19:37:19.010Z

Oh right

2019-08-20T19:38:21.010400Z

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

kenny 2019-08-20T19:41:14.010800Z

That quick-check wrapper fn should work for now

👍 1