Validation, meet Unit Testing. Unit Testing, meet Validation.

By anders pearson 20 Sep 2005

[cross posted from the WaSP to take comments]

Are you test infected? Do you work on dynamic sites and wish there was an automated way to run the output through the W3C validator? Do you wish it was integrated nicely with your unit testing framework?

Scott Raymond has come up with a nice bit of code to add automated validation to the unit tests for a Ruby on Rails application.

If you’re not on Rails, the technique should be pretty straightforward to adapt to your prefered language/framework. Just make a POST request to http://validator.w3.org/check sending parameters fragment (your page, encoded) and output=xml. Then check the response for a header called x-w3c-validator-status to see if it says Valid. If so, your test passed.

Tags: validation web standards extreme programming unit testing