Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add unit tests to a Leiningen project?

I noticed that leiningen has a great unit test plugin - you just enter "lein test" :) . However, it's not clear how it "finds" the test files. Is there a specific folder I need to put them in? Or, if its just scanning namespaces (which is what it says in the lein docs), how do I know what namespace I need to use for leiningen to see my tests?

I was thinking about simply making one test file, called tests.clj. A sample template would really be nice.

like image 989
jayunit100 Avatar asked Oct 14 '11 18:10

jayunit100


1 Answers

At the top level make a test/ directory, and then create some file, say mytests.clj. Here's a sample (caveat: I didn't actually compile this, but simplified an existing test):

(ns mytests
    (:use clojure.test))

(defn myfixture [block] 
    (do 
        (println "before test")
        (block)
        (println "after test")))

(use-fixtures :each myfixture)

(deftest mytest
    (is (= 2 (+ 1 1))))
like image 98
Kevin Avatar answered Dec 01 '22 09:12

Kevin