malli

Ivan Fedorov 2026-02-09T12:48:08.394189Z

Heyy! What do we respond to people asking about generative test tooling in malli these days? There's a library for it? Or everyone is just having their own 10 line solution to take malli's generator and run code with it?

2026-02-09T15:08:43.408069Z

It integrates well with test.check https://github.com/metosin/malli?tab=readme-ov-file#value-generation

(require '[clojure.test.check.generators :as gen])
(gen/sample (mg/generator pos-int?))
; => (2 1 2 2 2 2 8 1 55 83)
I was just fiddling in this space and wrote this
(defn validate-schema-roundtrip
  "Tests that a Malli-generated value passes JSON schema validation"
  [malli-schema json-schema-name]
  (prop/for-all [value (mg/generator malli-schema)]
    (let [json-value (m/encode malli-schema value mt/json-transformer)
          json-str (json/encode json-value)
          result (json-schema/validate registry json-schema-name json-str)]
      (when-not (:valid? result)
        (println "Validation failed for:" json-value)
        (println "Errors:" (:errors result)))
      (:valid? result))))
I wanted to see if my malli schemas generate values that are compliant with a json schema. Those printlns are there to just make it a little bit easier to see what's going on when it fails.

❤️ 1
Ivan Fedorov 2026-02-09T12:48:45.907759Z

I have a colleague whose only point for core.spec is generative tests