The test.generative library divides testing into three key steps:

  • Generating test inputs

  • Invoking test functions

  • Validating results

Each of these three steps is implemented via functions, which are then composed into tests via the defspec form.

Let’s install test.generative and take it for a spin. Add the following line to your project.clj:

 ​[org.clojure/test.generative "0.1.3"]​

Now execute whatever steps you use to reload project code and meet us at the REPL to generate some test data.

Generating Data

From the REPL, require the generators namespace as follows:

 ​(require '[clojure.test.generative.generators :as gen])​

The generators namespace contains functions to generate pseudorandom values for different common datatypes. ...

Get Programming Clojure, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.