Clojure: Default Unit Test Setup

Code for this project is on github.

So you want to test in Clojure, huh? Well good thing you found this oasis of awesomeness. Getting a test up and running is pretty easy, but involves a few simple steps that I will stretch out to the point of pain.

First off, start a new project. Again simple. Just let Linegen to do if for you:


Doing this should create a new project space age tubular frame:


Still with me? Good. Now for the test creation.


As you can see, I added a file with a test. What you might notice, or cause panic, is that I don’t have a file to test with this test file test. And that’s ok, because we’re @#$%ing this $@#% up Test First style. Basically, create a test, and then create what it’s supposed to test. I won’t get into Test First here, but just wanted to calm your concerns.

Now to run the test. This is done by opening up a command window, navigating to the root folder for your project (It will have a project.clj file in it), and typing

	lein test

Ruh roh. Looks like that file that isn’t in existence can’t be tested. Weird, right? Oh well, time to create it.


There are a couple points at this eh point. You will see that I added a file named “simple_math.clj” to the “test_example” folder.

Something I found out while I was creating this little gem of a tutorial; Apparently the convention for a folder is to use a _ where a class in a file uses a -. So as you can see, the folder “test_example” translates the namespace part “test-example”, and “simple_math.clj” becomes “simple-math”. From what I can tell, since I am pretty new to Clojure, lienigen will try to resolve the namespace of “test-directory.simple-math” to “test_directory/simple_math”. I assume this is part of the “convention over configuration” school of thought. Since I come from a .net background where conventions just don’t exist, it caught me off guard.

Anyways, since that is done, it’s time to run the test again.


One failure? Oh yeah, the junk test created by lienegin. Well, just get rid of that:


And run it again:


And things are looking a lot better.