« Math Puzzles | Main | Happy Holidays - 2008 »

WebTest - Grails Plugin

In my ongoing adventure of learning/using Grails/Groovy, I had stumbled across the WebTest plugin for Grails, available from Canoo. But I thought it would be hard to set up and difficult to use, so I avoided it for a while. I did add some basic integration tests using the built-in JUnit capabilities of Grails, but they were very limited and I didn't really use them.

As the Gift system got more complicated, the need for testing became clear - but it really had to be testing at the web page level, at what the user would experience - nothing lower-level would really do. So, I went and installed the WebTest plugin and started writing some tests.

I was very pleasantly surprised. Not only was everything drop-dead simple to install and start using, but the basic primitives (steps) integrated quite easily with my existing application - and the debugging of testing problems was also straightforward. After a little while, I had built up a solid library of testing functions that I could easily reassemble to cover a wide variety of use cases.

And yes, I finally did some work with test-driven development. I had been needed to add a new feature for a while, but I was concerned that it would be somewhat intrusive. So I wrote the test cases first, which is a grerat exercise for thinking about what the users will actually do. And then wrote code until all the test cases passed.

Today I needed to add another new feature - and used the test-driven approach again. Quite satisfying.

My experience with webtest has generally been very positive, although one thing to note is that you can't (easily, at all?) get values from web pages back into your Groovy code. What I mean by this is that say you add a new Gift to the system, you can get the newly created id back into a webtest property, but you can only use that property in future calls to webtest steps - you can't use that id to make a direct API call into your database (for example). In practice, this wasn't a limitation - and it might even be a feature - as it forces you to always act like a user - interacting through the actual UI, never going underneath the covers.

All in all, if webtest can get me to test driven development, it must be a good thing.

TrackBack

TrackBack URL for this entry:
http://landisfamily.dnsalias.org:90/cgi-bin/mt/mt-tb.cgi/168

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)