Property-Based Testing

While clojure.test is a fine implementation of traditional unit testing, it does suffer from the common drawback of all unit-testing frameworks. To test a given property of your code, you think of some examples that exercise that property and you start typing. The problem with this approach is that the tests are one step removed from the thing you’re really interested in: the property. For example, take another look at the first test we wrote in this chapter:

 (deftest test-finding-books
  (is (not (nil? (i/find-by-title ​"Emma"​ books)))))

A casual observer might be forgiven for thinking that this test has something to do with the novel Emma. It doesn’t. The test is trying to say that we should get a non-nil result when ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.