OSCON 2006: Rock-solid Web Development: Testing Web Apps

    Kevin Yank

    All this week, Kevin Yank is reporting from OSCON 2006 in Portland, OR.

    Presenter John Paul Ashenfelter provided the standard sales pitch for testing, but with a web development spin, and demonstrated both Selenium (a rich, in-browser testing framework that lets you write and run your tests using nothing more difficult than HTML and CSS) and The Grinder (a free load testing tool that can be cumbersome to use, but won’t cost you an arm and a leg). The slides and supporting materials from the tutorial are available on the TransitionPoint web site.

    Testing is a discipline in itself, with sub-disciplines like user testing, functional testing, and load testing. The desktop web development world—and to some extent, the enteprise web development world—is adopting all these types of testing at an impressive rate, but some of the unique challenges faced by web developers (e.g. multiple browsers) mean that testing is taking hold more slowly in that world. In this talk, Ashenfelter demonstrated the state of the art of testing in each of these sub-disciplines, where the tools involved range from the daunting to the inspiring.

    If you haven’t seen Selenium in action, you owe it to yourself as a web developer to at least download Selenium Core, extract it, open the index.html file, and run the built-in set of tests in Selenium TestRunner. Watch your browser (no matter which browser you use) immediately become a testing framework as it automatically interacts with a series of pages and verifies that they behave as they should.

    If you’re impressed, try your hand at writing a few tests yourself (hint: all you need to write is an HTML table), or take a look at Selenium IDE, a Firefox extension that can record user actions and generate a testing script on-the-fly.

    Less straightfoward is The Grinder, a free load testing tool written in Java, which is Ashenfelter’s tool of choice not because it is especially easy to use, but because it’s the only one that won’t cost you tens of thousands of dollars to use in the real world. The fact that it’s open source is just a bonus in this case.

    The Grinder works by recording your interactions with a site by configuring your browser to connect to the site through a proxy server. Those interactions produce a Jython (Python on Java) script that you can then tweak by hand. Once you’ve got a script, you can set up The Grinder to pommel your site with tens (or thousands) of instances of that script being executed at once.

    Ashenfelter admitted that load testing is not an easy problem to
    solve. He even suggested that if your testing target is nontrivial, you might
    just be better served paying a consulting firm to come in and do it for
    you. But for the do-it-yourselfers, The Grinder is a capable (if cumbersome) tool.

    Tying all your testing efforts together and getting your fellow developers to use the testing tools and pay attention to the results requires a little work as well, and Ashenfelter’s advice here was to use the standard tools like CruiseControl, and to set up “Information Radiators”—systems for developers to receive the results of automated testing in low-noise, high-profile ways that won’t get ignored (as, say, a daily email will).