O'Reilly logo

Clojure Applied by Alex Miller, Ben Vandgrift

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required