Mike West — Web Application Developer

I’ve been spending a lot of time recently attempting to puzzle out a good way of testing the work I’m been doing. I’m enamoured with the idea of unit tests, and I have the feeling that I could save myself a bit of misery if I had a mechanism to build tests for each bug I close. It’s a great dream, but I’m not coming up with much in the way of a solid solution for my work.

Sketching out the broad outlines of what I want is pretty simple. There are two broad categories of things I want to test:

  1. Core functionality: If I click on an article from some listing page, I should end up at the same article’s page. I shouldn’t ever see 404’s. PHP errors and warnings shouldn’t exist on the site.

  2. Presentation tests: Each module in the sidebar should be X pixels wide in all the A-Grade browsers. Text shouldn’t be cut off because of overflow issues. Thing X should be Y pixels away from thing Z.

Core functionality is easy, rather, I can come up with good ways of writing those tests. A spider is just a quick Perl script away, and the tests I want to do are almost completely doable with regular expressions. If a link’s text matches the headline of the page to which it leads, wonderful! If not, error! With a few hardcoded exceptions to handle “More” links and the like, I’ve got a solid testing system. Presentation, on the other hand, is hard.

It’s hard not because it’s terribly complex, it’s hard because it’s tremendously difficult for a computer to determine if a page looks right. The only test mechanism I’ve come up with is a convoluted system of JavaScript checks: grab an element’s computedStyle and run a series of checks. That covers a good chunk of presentational issues, but it’s incredibly timeconsuming to build out a testing system that way. Moreover, it only catches the subset of errors that are directly tied to the box model. I don’t really know how to generically test to see if a particular link is floated next to an image, or gets pushed under it, for example. Sure, I can check X and Y offsets and compare those to the image’s width and height, but those sorts of interdependencies get very complex, very quickly.

So I’m still looking. Selenium looks like something I should play with, even if the notion of writing tests using HTML table elements is somewhat disheartening. JSUnit is likewise a potential source of testing goodness. Any other good sources I should be taking a look at?

Mike West is a web application developer living in Munich, Germany. Professionally programming for the web since 2000, he's available for contract work now a web developer at Yahoo! Germany. Read Mike's bio, or drop him an e-mail.

Recent Articles


Comments

I’m not sure presentation tests can be tested mechanically. Beyond basic things like spacing between blocks, it is surely a matter of judgement whether something is presented properly. The nature of the web is that you aren’t going to get pixel-perfect rendering of everything between browsers and pages, especially with lots of different content.

Furthermore, do you necessarily trust the browser to report accurately what it has rendered and where if it has not rendered it according to the standards and styles you have specified?

Posted By: Bruce Boughton 18. May 2007, 13:53

Bruce, I more or less agree with you. It’s simply a problem that humans are much better able to handle than machines. Even with solid wireframes and well-specced page layouts, it’s often a matter of personal preference as to whether or not a layout is “right” or not.

That said, I think it’s possible to get the browser to explain to you in it’s own language what it’s up to. The YUI Dom library, for example, does a pretty good job mashing up all the browser quirks surrounding styles into a few methods that can fairly accurately locate elements on the page, and give you their measurements. Whether or not that’s enough to build a testing platform on top of, I don’t know. I do know that writing such a test would probably be painfully verbose (for the reasons you noted: “Does this look right?” is a more difficult question to express programatically than it sounds).

Posted By: Mike West 18. May 2007, 14:02

Comments Closed

Comments are closed after 6 weeks to avoid the icky comment spam we all loathe. Sorry if you missed the opportunity, but you can always drop me an e-mail!

flickr Photostream

Yahoo!'s Munich Office
atom:title
atom:title
atom:title