ala carte testing is easy, clojure comes with a testing library called
'clojure.test'

the simplest way to test functions is to define tests using deftest,
and to assert things using is

(use '[clojure.test :only [deftest is]])

(defn foo [x] (+ x 1))

(deftest test-foo ;; deftest creates a var, so needs to have a
different name from the function being tested
  (is (= (foo 1) 2)))

you can run all the tests in a namespace using (run-all-tests)

clojure.test includes a few other things (fixtures, are assertions,
testing blocks, etc) but is generally a simple bare bones library.

`lein test` is a task for the lein build tool that runs clojure.test
tests if your project is a lein project.

the lein convention is to package tests in a separate namespace from
what is tested.

 tests for the namespace foo.bar are in the namespace foo.test.bar.

the files backing test namespaces are also kept in a separate
directory, ./src vs. ./test

On Thu, Dec 8, 2011 at 1:10 PM, Brian Marick <[email protected]> wrote:
> I don't know if you got any answers. If you're not wedded to clojure.test, 
> the examples of Midje here may help:
>
> https://github.com/marick/Midje
>
>
> On Dec 1, 2011, at 12:30 AM, Adam Getchell wrote:
>
>> Hello,
>>
>> I'm porting a scientific application written in SBCL to Clojure. I'd like to 
>> do the right thing by setting up tests to ensure my functions are correct, 
>> and package up the project correctly using Leiningen.
>>
>> I've read "Clojure in Action", however, the sample code from Chapter 8, 
>> which details TDD, didn't work in my environment (I'm using IntelliJ + 
>> LaClojure).
>>
>> I've also read over the Leiningen tutorial here: 
>> https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md which 
>> makes a passing reference to using "lein test".
>>
>> However, I haven't put together how I should setup a proper test suite to 
>> generate tests for functions I have defined in, say, a file called 
>> "utilities.clj".
>>
>> Any pointers/hints? For example, what do I name a file such that my 
>> "deftests" get invoked by Leiningen correctly?
>>
>> Thanks,
>>
>> Adam Getchell
>> --
>> "Invincibility is in oneself, vulnerability in the opponent." -- Sun Tzu
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> Note that posts from new members are moderated - please be patient with your 
>> first post.
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>
> -----
> Brian Marick, Artisanal Labrador
> Now working at http://path11.com
> Contract programming in Ruby and Clojure
> Occasional consulting on Agile
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

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

Reply via email to