Example-Based Tests with expectations

The expectations library[23] takes the ideas of clojure.test and pushes them further with the goals of simplified test definition and improved feedback. In expectations, every test is a bare form with a single assertion.

For example, rewriting our first clojure.test examples with expectations looks like this:

cljapplied/src/ch8/expect.clj
 
(expect '(0 1 2 3 4) (​range​ 5))
 
(expect '() (​range​ 0))

Each expect at the top-level of the namespace takes an expected value and an expression and checks that the expectation is satisfied.

A number of other special expectations forms test various special cases. For example, passing an exception type will check that the form throws that type:

cljapplied/src/ch8/expect.clj ...

Get Clojure Applied 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.