philipbohun.com

Glojure by Example: Testing

clojure.test is the bundled test library. deftest defines a test, is asserts an expression, and run-tests runs the tests in the current namespace. A passing test prints a short summary.

(ns sample-test
  (:require [clojure.test :refer [deftest is run-tests]]))

(deftest addition
  (is (= 4 (+ 2 2))))

(run-tests)

A failing is prints the expected expression and the actual value. Put tests in their own namespace, as this file does, so they do not land in clojure.core.

One assertion, and it passes.

$ glj testing.glj

Testing sample-test

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

Next example: Command-Line Arguments.