Skip to main content

On the testing of UI web applications

Posted by johnsmart on April 9, 2007 at 4:25 PM PDT

For me, testing the user interface layer in web applications has always been a weak link in the chain. You can use unit testing pretty effectively to test-drive your development for most other application layers. (As an aside, I find it quite acceptable to use an in-memory database such as HSQLDB to unit-test DAO components - it's fast, easy to set up, and avoids having to muck round with mock objects and the like. There are also tools such as DBUnit to help out in this area). However, testing the screens themselves has always been a problem.

Of course, you can try out the heavy-weight tools from the likes of Mercury and Rational. Fine tools I'm sure, but pricey. AFAIK, these tools also assume you have a (more or less) working system to write your scripts against, which is not really what you want for test-driven development (though it might be appropriate for functional testing big applications).

Frank Cohen has developed an interesting-looking O/S tool called TestMaker, which lets you record web tests in Jython, edit them, and replay them as unit tests. This one is on my list of tools-to-test.

StrutsTestCase is a neat little tool that lets you design light-weight unit tests of your Struts actions by simulating . However, as the name suggests, it only works for Struts, which is a bit of a shame if you are using JSF, Tapestry or some other up-and-coming framework. It would be nice to have the same thing for JSF - where you could test pages from within JUnit or TestNG without having to start up a web container. I've never heard of such a project, though...

There are also other JUnit extensions such as HTML Unit, HTTP Unit and Cactus, which run unit tests against a running web application. These should really not be called unit tests, as you need to build, bundle and deploy your application before you can run them. Compared to something like StrutsTestCase, this makes for a much longer development cycle, which I don't particularly like. It would be nice if they could start up their own in-memory Jetty server and run the tests against that.

I've also never really been able to get my head around Cactus - AFAICT you need to deploy and run your unit tests on the application server, which seems a bit messy.

With the advent of AJAX-based user interfaces, debugging Javascript-based user interfaces has added new challenges. One radically-different approach is to simulate user actions directly within a browser. Selenium (from the folk at ThoughtWorks) lets you record and execute tests within your browser. And FireBug lets you test and debug Javascript, CSS and HTML from within the browser.

Testing tools are starting to take up a sizable chunk of the Java Power Tools book, which is probably logical, as proper and efficient testing should play a sizable part in any development process worth its salt. I've added a new poll on web UI testing tools "http://www.javapowertools.com/web-testing">here - please take a look and let the world know your favorite web UI testing method!