We don't really have enough tests. We deploy to production when stuff "seems to work". Mostly that stuff actually does work, but when something's broken it's pretty painful to fix live. I don't know a lot about testing in clojure, or about testing websites. It looks like @gigasquid knows the most about Midje, which is a tool that I think looks really cool but could never figure out how to use. Does anyone know how we can write meaningful tests for 4clojure, so that we can deploy with confidence?
I agree with the need for more tests. The part I struggle with is trying to break apart the methods to test without the db or session stuff. I would love to have an integration test to - like Ruby's Capybara - but I don't know of any for Clojure.
Why do we need to break apart the methods though? Shouldn't we be able to setup/teardown a testing db with Midje? 4Clojure is already pretty good about creating the db from scratch at startup right? This might be totally wrong, since I don't know much about unit testing in Clojure either.
@dbyrne - Yes we could setup and teardown with Midje. I understand how to do that with the database, but how could we handle the session stuff - like (session/session-get :user) ?
I was talking with the integration test idea with @ckirkendal. He put together a code example using his Clojure-Given framework. I haven't had a chance to try it yet -- but it might be an interesting path ... Example:
(Given! [browser (com.gargoylesoftware.htmlunit.BrowserVersion/FIREFOX_2)
client (new com.gargoylesoftware.htmlunit.WebClient)])
(Given [start-page (.. client (getPage url))])
(Context "login page -->"
(Given [url "http://4clojure.com/"])
(Given! [login-link (.. start-page (getElementById "login"))])
(. login-link click))
(Then (.. login-page asText (contains "Username")))
(Then (.. login-page asText (contains "Password")))
(Context "login -->"
(Given! [uname (.. login-page (getElementById "user"))
pwd (.. login-page (getElementById "pwd"))
form (.. login-page (getForms) (get 0))
lbut (.. form (getButtonsByName "") (get 0))])
(.. uname (setText "<USERNAME>"))
(.. pwd (setText "<PASSWORD>"))
(. lbut click))
(Then (.. welcome-page asText (contains "Logged in"))))))