Want this course?
Course: Intro to clojure.test
We briefly discuss why we should learn clojure.test and become acquainted with our characters, Josie and Ignacio, who use a few namespaces to keep track of their fitness routines. We need to help them develop tests.
Josie and Ignacio like to keep fit. They work out regularly and test their fitness every week. Our job is to help them develop a fitness test to make sure they are in peak condition. We’ll make the fitness tests into automated tests.
The most popular testing library is called clojure.test. It’s used in 31,000 Clojure files on Github. It comes built-in with Clojure. There are no extra dependencies. It’s no wonder it’s used by other testing tools and utilities. It is a must-know for serious Clojure programmers.
The fitness routines we’ll be using are available in a Github repo. You should clone that repo now. You can find the command below the controls:
> git clone https://github.com/lispcast/intro-clojure-test.git
That should download the code you’ll need to follow along, spin up a REPL, and do the exercises.
You should clone it a second time, like this:
> git clone https://github.com/lispcast/intro-clojure-test.git intro-clojure-test-fresh
That will clone the same repo into
all of your changes to the first one (
intro-clojure-test). You can
then nagivate the
intro-clojure-test-fresh more easily with commands
you’ll see on the exercise pages. Both repos contains all of the code,
including code that is the answers to the exercises. If you ever get
stuck or want to skip around, you’ll be able to copy the code from
fresh into your working directory. If you are very familiar with
git, feel free to use a single repo.
Open up your editor and you’re ready to go!
Josie and Ignacio have three different namespaces where they organize
the exercises. There’s
of those namepsaces has functions for doing the exercises. In
Now where do we put the tests?
clojure.test does not tell us where
to put the tests, except that they have to be in a namespace. So we
can put them alongside the functions that they are testing.
Another possibility is to make a namespace, let’s say
where we put all of the tests. So regardless of what namespace the
function is we’re testing comes from, we can put all the tests in
But we all know that throwing a bunch of unrelated stuff together into a big bag can get very disorganized.
So the best way to do it is to have a namespace called the test
namespace that corresponds to the namespace that you are testing. So
upper-body will have a corresponding namespace called
upper-body-test. And you’ll put all the tests for
Code is available: lispcast/intro-clojure-test
You can checkout the code in your local repo with this command:
$CMD git clone https://github.com/lispcast/intro-clojure-test.git $CMD cd intro-clojure-test