What is Midje?
masterclojure.test. It is designed to be used idiomatically within a REPL, allowing for rapid development cycles where tests are automatically re-run upon file changes while maintaining an interactive prompt.repository·master·Indexed 23 days ago
https://github.com/marick/midjeA Clojure testing framework designed for readability and ease of use, making tests resemble executable code examples. Midje supports top-down and bottom-up testing, provides a migration path from clojure.test, and is optimized for REPL-driven development. The framework utilizes a three-step parsing pipeline—converting implicit syntax to explicit forms, generating lexical maps for scope handling, and final evaluation—and includes specialized macros such as tabular and formula.
clojure.test. It is designed to be used idiomatically within a REPL, allowing for rapid development cycles where tests are automatically re-run upon file changes while maintaining an interactive prompt.Midje uses an implicit syntax for defining facts, where examples and prerequisites are identified by their structure rather than explicit function names like (example ...) or (prerequisite ...).
Implicit Syntax Example:
(facts "about my-fun"
(myfun 3) => 4
(myfun -1) => 4
(provided
(helper 1) => 2
(helper 2) => 2))During the first step of parsing, this is converted into an explicit internal representation:
Explicit Form Equivalent:
(expect (myfun 3) => 4)
(expect (myfun -1) => 4
(fake (helper 1) => 2)
(fake (helper 2) => 2))Midje's parsing engine transforms implicit fact syntax into evaluated results through a three-step pipeline. While users typically interact with the implicit syntax, understanding this pipeline helps in debugging how facts are expanded and evaluated.
expect and fake forms.let block).To ensure that facts can correctly access variables from their surrounding lexical context (like a let block), Midje converts explicit forms into "lexical maps".
If you write:
(let [a 1]
(fact (* a 1) => a))Midje does not evaluate (* a 1) immediately. Instead, it creates a lexical map that stores the un-evaluated forms. This allows the engine to evaluate the forms later in the correct context where a is defined.
A representative lexical map looks like this:
{:function-under-test (fn [] (* a 1))
:expected-result a
:expected-result-form 'a}Midje is available as a dependency via Clojars. You can add it to your Clojure project using your preferred dependency management tool (such as Leiningen or Deps.edn) by referencing the midje artifact on Clojars.
https://clojars.org/midjeMidje provides two primary macros that wrap facts to provide specialized syntax or behavior:
tabular: Used for defining facts in a tabular format.formula: Used for defining facts using formula-based syntax.These macros expand into the standard fact-processing pipeline.