A new way to test (to me?)

Purdy on 2009-01-03T03:29:26

It's a shame all of my code can't reside in the tidy confines of my Perl libraries - from time-to-time, I have to write JavaScript for a better browser experience. If you haven't heard, Yahoo's YUI has a testing framework (YUITest) that is pretty neat and I'm now using it (vs. Selenium).

Granted, I wasn't heavily invested w/ Selenium, so switching wasn't really that much of a hurdle. But YUITest is pretty cool stuff. I will tell you that it's no Test::More. It doesn't have cmp_ok, so you have to program around it a bit. And you have to program in JavaScript, itself.

What I found as a neat approach is to write the self-contained YUITest code in a separate file in a template directory (i.e. selectTest.yuit).

Then in my app code, I pass along a conditional template parameter that will include that .yuit template contents and then tie that to a query parameter ... i.e.

http://www.example.com/myApp.cgi

And that'll run the app as usual. Then if I append ?t=1, then my app will suck in the .yuit file, which brings in the YUITest framework and runs it. You could get more advanced and automate it and use the framework's reporting functionality to make things even more robust.

Peace,

Jason


HtmlUnit

awwaiid on 2009-01-04T06:17:14

I recently wrapped the java HtmlUnit library in Perl (see CPAN) -- it is kinda like WWW::Mechanize except with a fairly functional javascript engine. I don't know if it'll run the YUITest framework, but it might be worth a try. I hope to also wrap the Mechanize API and eventually have Test::WWW::Mechanize::HtmlUnit or similar.