Clojure unit testing frameworks
Unit testing[6] is the testing of an individual software component or module. Clojure provides a number of testing frameworks for unit testing.
Let's create a Clojure project where we can write our tests, using the following command: lein new testing-example
.
The clojure.test framework
The clojure.test framework (http://clojure.github.io/clojure/clojure.test-api.html) is the default Clojure unit testing framework that comes with the Clojure standard library. By default, Leiningen creates a testing directory with each new project:
$ tree test
├── test
│ └── testing_example
│ └── core_test.clj
This directory has one test file, called core_test.clj
:
(ns testing-example.core-test (:require [clojure.test :refer :all] [testing-example.core :refer :all])) (deftest a-test (testing "FIXME, I fail." (is (= 0 1))))
This file imports the Clojure testing namespace, as well as the core file from the src
directory. The file contains one test method. Let...