Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strengths of Clojure testing frameworks?

Which one do you prefer and why? What are the pros and cons of each? In which scenario does each outshine the others?

I'm particularly interested in midje vs. clojure.test, but feel free to bring up other Clojure testing frameworks too.

See also Best unit testing framework for Clojure? (the answers to that question didn't provide much detail on the "why").

like image 299
bshanks Avatar asked Oct 10 '11 09:10

bshanks


1 Answers

I haven't tried them all, but I like plain old clojure.test for the following reasons:

  • It's already there in the Clojure API: No extra dependencies.
  • Integrates well with Maven: I use Eclipse with the clojure-maven-plugin to ensure that both Clojure and Java tests get run automatically whenever I build.
  • It's simple: 99% of what I need in testing is just to be able to write a well structured set of assertions, clojure.test makes that pretty easy

Sample code:

(testing "Arithmetic"
  (testing "with positive integers"
    (is (= 4 (+ 2 2)))
    (is (= 7 (+ 3 4))))
  (testing "with negative integers"
    (is (= -4 (+ -2 -2)))
    (is (= -1 (+ 3 -4)))))
like image 74
mikera Avatar answered Oct 16 '22 08:10

mikera