I'd like to formally announce Midje, a testing framework for Clojure that 
emphasizes ease of use, readability, and relationships among functions.

    https://github.com/marick/Midje

Midje is at 0.8.1. I'd bump it to 1.0. but I don't want to freeze the interface 
to some of the newer features just yet. 

Here's a simple example:

    (fact (+ 1 1) => 2)

I use the word "fact" because Clojure is a functional language. State 
modification should be rare. That means that most code will always produce the 
same value: when you write tests, you state facts about a function that readers 
can generalize from. (In mathematical terminology, Midje facts are propositions 
with no variables that encourage readers to assume universally-quantified 
propositions.)

Midje makes it easy to use functions other than equality to check results:

    (facts 
     (first (primes-greater-than-2)) => odd? 
     (some-complicated-function) => (in-any-order [1 2 3]))

Midje lets you alternate between bottom-up (REPL-based) and top-down design. In 
the latter, you claim facts about functions that are true *provided* facts 
about not-yet-written functions are true. That looks like this:

    (fact
     (alive-in-next-generation? ...cell...) => truthy
       (provided 
        (alive? ...cell...) => false
        (neighbor-count ...cell...) => 3))

The above is an example I wrote in one of Corey Haine's Code Retreat workshops. 
It lets me worry about the properties of "aliveness" in Conway's life before I 
worry about the concrete representation of the Life board. 

The ...cell... notation shows what I call "metaconstants". I've long thought 
that useful tests live somewhere between concreteness and abstraction. 
Metaconstants let you say of data "Assume nothing about this data except what's 
explicitly stated here." In my programming, I've found metaconstants far 
preferable to creating complicated data structures (via "fixtures", "object 
mothers", and the like). It's been a big help in test maintenance. (Most of my 
experience with this has been in Ruby, but it seems to apply to Clojure too.)

Midje contains other features you might expect from a test framework. For 
example, when you have to use state, it gives you a way to set it up or tear it 
down:

     (fact
       (against-background (before :checks (swap! test-atom (constantly 0))))
       (swap! test-atom inc) => 1
       (swap! test-atom dec) => -1)

    (background (around :facts (sql/with-connection db ?form)))

I've worked up an emacs interface, and there are features I'd like other test 
frameworks to steal (like "chatty checkers"). 


It will make me happy if you try Midje.

-----
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Author of /Ring/ (forthcoming; sample: http://bit.ly/hfdf9T)
www.exampler.com, www.exampler.com/blog, www.twitter.com/marick

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to