Writing and running our first test
We're going to create a few tests for the validators we created in Chapter 5, Handling Form Input. In our directory structure, we have the src
and test
directories. I'll give you two seconds to determine under which directory our tests should go… got it? If you said src
, then I have failed to achieve the modest task that was my charge. We will be storing our tests in the test
directory using the following steps:
Create a directory in the
/test/hisptr/test
directory calledvalidators
.Create a file in the
/text/hipstr/test/validators
directory calleduser_validator_test.clj
.In
user_validator_test.clj
, define our namespace and include theclojure.test
namespace and the namespace we wish to test—in our case, thehipstr.validators.user-validator
namespace:(ns hipstr.test.validators.user-validator-test (:require [hipstr.validators.user-validator :as uv]) (:use clojure.test))
Next, let's add a test that ensures only one error message is returned in the errors...