liveBook · Manning

Are

As explained in Clojure: The Essential Reference

are is a clojure.test macro that evaluates a family of similar assertions by substituting multiple argument values.

are is a clojure.test macro for evaluating a family of similar assertions. It substitutes successive argument values into a shared assertion form, reducing repetitive test code while reporting each failing case. section 22.9

Testing several inputs with one assertion

(deftest sqrt-test (are [x y] (= (sqrt x) y) 9 3 0 0 Double/NaN Double/NaN)) (test-var #'sqrt-test) ;; Reports a failure for each argument pair that does not satisfy the assertion. section 22.9

(require '[clojure.test :refer [are deftest test-var]])

(deftest sqrt-test
  (are [x y] (= (sqrt x) y) ; #1
    9 3
    0 0
    Double/NaN Double/NaN))

(test-var #'sqrt-test) ; #2

;; FAIL in () (form-init7968799.clj:2)
;; expected: (= (sqrt 9) 3)
;;   actual: (not (= 3.000000001396984 3))
;;
;; FAIL in () (form-init7968799.clj:2)
;; expected: (= (sqrt 0) 0)
;;   actual: (not (= 6.103515625E-5 0))
;;
;; FAIL in () (form-init7968799.clj:2)
;; expected: (= (sqrt Double/NaN) Double/NaN)
;;   actual: (not (= 1.0 NaN))

Inspect the complete are example, including its argument pairs and the resulting failure reports. section 22.9

How Clojure: The Essential Reference covers it

How deep it goes
Explains the substitution pattern and demonstrates per-case failure output, without detailing macro expansion internals.
Examples
Tests a square-root function with ordinary values, zero, and Double/NaN.
What it assumes
Assumes familiarity with Clojure test definitions and assertion expressions.
What you can do after
Apply it via clojure.test to express table-like families of related assertions.
How it connects
Connects are with clojure.test, deftest, test-var, and assertion forms.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.