Generative testing with Spec and Spec Test

Clojure spec has been used so far to create specifications for both data and functions.

Now spec and spec test libraries are used not just validity checking, but also to generate random samples of the data that can be used for extensive testing.

Generative testing provides a far more effective alternative to unit testing.

clojure.spec.test/check/instrument verifies that calls to a function satisfy the function's specification, the :arg in fdef.

clojure.spec.test/check function generates 1000 data values to be used as the inputs to a function, checks that the invocation of the function satisfies its specification, the :ret and :fn in fdef. The argument specification, :arg in fdef is used to generate a wide range of results, which are more capable of finding edge cases that fail.

Example: card game

practicalli/spec-generative-testing is a simple card game with specifications that are used for basic generative testing.

References

(->> (spec-test/check `function-with-a-spec) ,,, ;; test more functions ?? (spec-test/summarize-results))

(spec/exercise-fn ..

results matching ""

    No results matching ""