More testing #135

Open
amalloy opened this Issue Oct 1, 2011 · 4 comments

Projects

None yet

3 participants

@amalloy
Member
amalloy commented Oct 1, 2011

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?

@gigasquid
Member

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.

@dbyrne
Member
dbyrne commented Oct 15, 2011

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.

@gigasquid
Member

@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) ?

@gigasquid
Member

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:
(ns clojure-given-examples.test.core
(:import (com.gargoylesoftware.htmlunit.WebClient))
(:use [cljgiven.core]))

 (defspec basic-user
  (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"))])
           (When login-page 
             (. 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))])
                (When welcome-page
                  (.. uname (setText "<USERNAME>"))
                  (.. pwd (setText "<PASSWORD>"))
                  (. lbut click))
                (Then (.. welcome-page asText (contains "Logged in"))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment