|Do you know where your variables are?|
General web application testing advice sought.by fenLisesi (Priest)
|on Apr 13, 2007 at 16:04 UTC||Need Help??|
fenLisesi has asked for the
wisdom of the Perl Monks concerning the following question:
O wise ones,
For the last few days, I have been writing tests for a typical RDBMS-backend, web-frontend, Perl-in-the-middle application. One of the main tools in my arsenal has been WWW::Mechanize.
I browsed the source for WWW::Mechanize and its ancestors a bit (<heavenly-voice>use the source, luke</heavenly-voice>) -- and Data::Dumper::Dumper'ed the form -- to end up with this hold-your-mutable-internal-organs-and-twist-them move:
Aaand, chalk up another one for talk-to-your-teddy-bear. I just looked at the docs again (<homer>stupid heavenly-voice!</homer>) and saw that the following straightforward snippet is possible:
At any rate, I would appreciate some web application testing advice.
While I am at it, here is a pet peeve: If you set up your test code in OO fashion, then use'ing Test::* modules both in the ancestor and in the child causes problems due to multiple plans. The right way seems to be to, for example, use Test::More, in the ancestor, have all your ok(...)'s in that ancestor module inside subs like num_checkboxes_is(...), then call those subs from the descendants. Perhaps that's better anyway, as it keeps all the ok(...) and friends toghether there.
I wrote some unit tests last year using Test::Class and that was nice, smooth sailing.
Coming back to WWW::Mechanize again, I find myself doing things like:
where gen_tree returns an instance of HTML::TreeBuilder and check_for_input(...), implemented in the base class, uses look_down(). I do this because I have used HTML::TreeBuilder before and look_down() is a simple concept.
Since $mech already has all the structure of the document, though, it seems to be a waste to generate another big tree just because look_down() is flexible and simple. I have thus far ignored this waste, because, I don't care so much whether the smoke tests run between 3am and 4am or between 3am and 4:30am.
Test::WWW::Mechanize looks like the go-to guy in 4 cases out of 5, but a quick look at the docs gave me the (probably false) impression that it did not have the flexibility of look_down().