Skip to content

Testingλ︎

There are many aspects to testing software throughout the development lifecycle.

Category Description
Unit testing Assertion based testing of specific functions (units)
Specification testing Checking data and functions conform to clojure.spec specifications
Generative testing Automatically generated data to test specifications
Integration testing Tests across system components and multiple systems, typically during the build process
Performance testing Measuring the resources taken during function calls and system events
Load testing Measuring the capacity for the system to manage concurrent events

Unit testingλ︎

clojure.test is the de facto unit testing framework for Clojure. Tests have a simple syntax using deftest to contain multiple assertions defined with is. It is part of the Clojure.core library and therefore accessible to all Clojure projects.

expectations.clojure.test library can be added to clojure test to provide expectations style assertions (expect, more, more-of, etc.).

Specification testing - clojure.specλ︎

Defining specifications around functions and data structures, testing to ensure those contracts are not broken. Instrumentation of functions ensures that function calls follow specifications, including arguments, return values and a relationship between both.

Generative Testingλ︎

Tests are only as good as the thought that goes into them. Generative testing can create a wider range of testing scenarios by providing generated data for tests. This approach is very good at catching conditions that were not considered.

Integration testingλ︎

Continuous Integration (CI) services CircleCI, GitHub and GitLabs all support Clojure projects.

Clojure has several test runners that can be used with CI servers and practicalli/clojure-deps.edn defines a range of aliases for Clojure test runners.

  • :test/run to run lambdaisland/kaocha test runner, which is configured to stop immediately if any tests fail, minimising the time the CI workflow is running.
  • test/cognitect to run cognitect-labs/test-runner, a light-weight test runner

Performance testingλ︎

Tesing the execution time of specific functions or groups of functions, typically within a namespace.

time is a quick and easy tool to give a rough comparison of performance.

criterium provides more accurate guidance on performance

Load / Stress Testingλ︎

Testing the whole system under load that simulate the stress the system would be placed under in normal production environments.

Gattling is a JVM load tool.

There are many on-line load testing tools if you have a web facing application.