Testing private functions in Clojure
Let’s suppose there’s this function:
;; src/mypackage.clj
(ns mypackage)
(defn- my-private-function
[x]
;; For simplicity, just return the input
x)
You can test it like this:
;; test/mypackage_test.clj
(ns mypackage-test
(:require [mypackage :as p]))
(deftest test-my-package
(let [function-to-test (var p/my-private-function)]
(testing "happy path"
(is (= 42 (function-to-test 42))))))