Book Image

Clojure Web Development Essentials

By : Ryan Baldwin
Book Image

Clojure Web Development Essentials

By: Ryan Baldwin

Overview of this book

Table of Contents (19 chapters)
Clojure Web Development Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Anatomy of a test


There are three macros in the clojure.test namespace, which are the trifecta of testing in Clojure: deftest, is, and testing. These three macros are explained as follows:

  • deftest: This is similar to def or defn and defines our test function. Tests may call other tests, however, this is a practice that I consider dangerous, as it can result in fragile tests that are, by their nature, rather difficult to debug.

    Usage: (deftest name & body)

  • is: This is used to make an assertion in our test. The predicate we pass to is should return a Boolean. We can also optionally provide a message, which will be attached to the assertion and displayed as part of the failure written to stdout.

    Usage: (is form)

    (is form message)

    is also allows the following two special forms that can be used to check for exceptions:

    • thrown?: This is used to ensure that an exception of a specific type is thrown, and if not, fails the test.

      Usage: (thrown? e form)

      Here's an example of this form:

      ...