Generative testing
Another form of testing is generative testing, in which we define properties of functions that must hold true for all inputs. This is quite different compared to enumerating the expected inputs and outputs of functions, which is essentially what unit tests and specs do. In Clojure, generative testing can be done using the test.check
library (https://github.com/clojure/test.check). This library is inspired by Haskell's QuickCheck library, and provides similar constructs for testing properties of functions.
Note
The following library dependencies are required for the upcoming examples:
[org.clojure/test.check "0.9.0"]
Also, the following namespaces must be included in your namespace declaration:
(ns my-namespace (:require [clojure.test.check :as tc] [clojure.test.check.generators :as gen] [clojure.test.check.properties :as prop] [clojure.test.check.clojure-test :refer [defspec]]))
The following examples can be...