In the Wild

To find an example of clojure.test in real-world code you need to look no further than the tests for Clojure itself.[24] Here, for example, is a Zenlike statement of what + should do:

 (deftest test-add
  (are [x y] (= x y)
  (+) 0
  (+ 1) 1
  (+ 1 2) 3
  (+ 1 2 3) 6
 
  (+ -1) -1
  (+ -1 -2) -3
  (+ -1 +2 -3) -2
 
  (+ 1 -1) 0
  (+ -1 1) 0
 ;; Much of the test omitted.
  ))

Note that as part of its meditations this test uses are instead of is. Essentially are lets you build parameterized tests. The key logic is the (= x y) at the top, while the bulk of the test specifies values for x and y.

And here we have a test of the cons function.[25] Did you know that you could cons characters onto a string to get a sequence of characters? ...

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.