Tuesday, May 08, 2007

Acceptance Testing in Ruby

I'm teaching myself Ruby with the help of a 'toy' project. Sometime ago I wrote PerlActor, an Acceptance Testing framework that was inspired by Exoftware's Exactor open source project. I thought it would be educational and fun for me to port my Perl effort to Ruby. I've made good progress to date and I've learnt a lot about Ruby along the way. However, a question arises: Is an Exactor / PerlActor style testing framework useful for Ruby projects?

Exactor and PerlActor express tests in a simple language specific to the domain under test. They take an approach similar to FIT, but with test cases stored in simple text files, rather than embedded in HTML tables. By way of an example, a typical PerlActor test, in this case for a web application, might look like the following:


NewUserAgent
GoTo http://www.google.com/
PageTitleShouldContain Google


'GoTo','NewUserAgent' and 'PageTitleShouldContain' are commands, which are domain specific and either provided by the framework or implemented by the user of the framework. Exactor comes with a library of such commands. PerlActor is more basic, with the supplied commands really just being examples.

IMHO, a big selling point of this approach to testing is the customer-friendliness (in the Agile sense) of the tests. The test cases are very readable and it's possible for customers to write their own acceptance tests without needing to learn a complex syntax.

With Ruby's excellent support for meta programming, it may be possible to express such tests in Ruby code, while keeping the syntax as clean as the above. I'm not sure how to acheive this level of simplicity in Ruby and so I would be interested in hearing your opinions.

4 comments:

Darragh Curran said...

I agree with your comments on the value of the exactor approach. Check out http://blog.peelmeagrape.net/2007/5/8/exactor-style-at-in-ruby-spike for a quick spike of implementing exactor in ruby.

Tony Byrne said...

Thanks for the spike, Darragh. Your code is elegant and educational and it has given me some pointers for cleaning up the internals of my own code.

Chris Gallagher said...

I created something similar a while back but dont have the code to hand at the moment. I chose not to go down the route of using hpricot or any of those other plugins and extracted what was required by first converting everything to RXML and then using XPATH to pick out the elements.

Tony Byrne said...

CG, the Exactor approach has wider applicability than just testing web applications. Darragh's spike used hpricot because my example was a test one might use in a web application. However, Exactor commands can wrap or drive anything so long as you have access to an API.