Fork me on GitHub
#testing
<
2020-07-04
>
Joe14:07:54

For generative testing, is it a good idea to do stest/check on your functions as part of CI? If so, is there a common way to included them in your deftest's so they get called?

practicalli-johnny16:07:24

Apparently kaocha test runner will run specifications automatically, so this could be used as your test runner in the CI environment. https://cljdoc.org/d/lambdaisland/kaocha/1.0.632/doc/automatic-spec-test-check-generation Next weekl I'm going to try kaocha locally to run spec and then try kaocha on CircleCI. CircleCI has a kaocha orb which is a simple way to add common functionality to a build https://circleci.com/orbs/registry/orb/lambdaisland/kaocha

😲 3
Joe17:07:40

Nice, look forward to it!

plexus04:07:49

Yes, Kaocha has first class support for this, it might still need improving though. If you have feedback please drop into #kaocha. Same thing for the Cirlce CI orb.

👍 3
robertfw20:07:27

I have a little helper function for doing this.

(defn check-ns-fdefs
  ([ns-sym-or-syms]
   (check-ns-fdefs ns-sym-or-syms 1000))
  ([ns-sym-or-syms num-tests]
   (let [summary (-> (stest/enumerate-namespace ns-sym-or-syms)
                     (stest/check {:clojure.spec.test.check/opts
                                   {:num-tests num-tests}})
                     stest/summarize-results)]
     (is (= (:total summary) (:check-passed summary))
         "generative check test failed, see output for details"))))
and then in a test namespace i can use
(deftest check-fdefs
  (check-ns-fdefs 'some.namespace 100))

robertfw20:07:24

not a perfect integration but does the job

Joe10:07:05

Thanks, stealing this!