Skip to content

Testing in Clojureλ︎

Testing is supported in Clojure with a range of testing libraries and test runners.

Unit Testλ︎

The unit of test in Clojure is the function, so functions are defined that test other functions.

clojure.test namespace is part of the Clojure standard library and provides assertion based testing and functions to run tests.

Practicalli Unit Testing Guide Using Test Runners

Generative testingλ︎

Define specifications for values to confirm information coming into and leaving a Clojure service are of the correct form.

Generate test data from value specifications to verify the behaviour of functions, creating diverse sets of data for extensive testing.

Define specifications for functions to validate the correct form of values are passed and returned from a function.

Define value and function specifications with Cloure Spec Generative Testing with Clojure Spec

Performance testingλ︎

Test individual expressions through to application and load testing one or more services.

  • time - simple results of evaluating an expression
  • criterion - a realistic measure of performance for clojure expressions
  • Gatling - open source & commercial load test tool for web applications
  • clj-gatling - wrapper around Gatling which enables tests to be expressed in Clojure.

Behaviour Driven Development frameworksλ︎

Although not widely used in the Clojure community, there are several approaches to develop and test software using Behaviour Driven Development.

BDD: Given, When, Then and scenario approach to outside in software testing

  • Scenari - executable specification / BDD in Clojure
  • kaocha-cucumber - support for Cucumber tests in the gerkin format
  • speclj - TDD/BDD framework for Clojure and ClojureScript based on RSpec.

Alternative BDD libraries are discussed at https://github.com/gphilipp/bdd-guide-clojure

Articles on testing in Clojureλ︎