Filipin.eu

Željko Filipin's blog.
Home Blog Tags License

View on GitHub
10 November 2006

Tests and How-To Documents

by Željko Filipin

You have a bunch of tests, right? With every build of your application under test, you run them all. If a test fails, application should be fixed, or you test should be fixed. Wouldn't it be nice to make how-to documents from that tests?

Time for an example (Ruby, Watir):

def login_as(username, password)
  ie.goto("my.app/login")
  ie.should_contain("please login")

  ie.text_field(:id, "username").set(username)
  ie.text_field(:id, "password").set(password)
  ie.button(:value, "login").click
  ie.should_contain("logged in as #{username}")
end

You run that test, and you get output like this (this is real output from my test):

log in
- go to '[application url]/login.aspx'
- (url should be '[application url]/login.aspx')
- (there should be text 'Please Login')
- at text field 'userName' enter '[userName]'
- at text field 'password' enter '[password]'
- click button 'Login'
- (url should be '[application url]/default.aspx')
- (there should be text 'Recent Contributions')
- (there should be text 'logged in as [first name] [last name]')

I posted this at wtr-general list and people recommended to take a look at rSpec and Systir.

tags: code - ruby