in reply to A test harness for scripts

I've had some very good success with the Test::Cmd distro, when testing commandline stuff. I used it to test something that was going to be run in a batch mode, ending up with over 200 tests in less than a month of ad-hoc development. This works equally well for commandshell and batch, cause batch is really just commandshell w/o an active user.

As for web scripts, I've been getting some good traction using a combination of the following:

  1. Structure the application using CGI::Application and with good modularization. Standard 'make test' works for the API. (My current app is split into 9 CPAN-like distributions and one catch-all install including the templates, CSS, and C::A bootstrap scripts.)
  2. WWW::Mechanize, which not doing look-and-feel very easily (you have to source-dive the HTML) and not handling JScript events (you have to implement them yourself in the test script), it does do a good job of spot-checking the result. Plus, it nicely handles redirects and the like.

Good luck!

------
We are the carpenters and bricklayers of the Information Age.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: A test harness for scripts
by petdance (Parson) on Feb 10, 2004 at 02:13 UTC
    WWW::Mechanize, which not doing look-and-feel very easily (you have to source-dive the HTML)

    You need to discover the mech-dump tool that comes with WWW::Mechanize. You feed it a file on disk, or a URL, and it tells you all the forms and fields on it.

    $ mech-dump http://perlmonks.org GET http://perlmonks.org/index.pl node= go_button=Search (submit) POST http://perlmonks.org/index.pl node_id=131 (hidden) op=login (hidden) user= passwd= (password) expires=<UNDEF> (checkbox) [*<UNDEF>/off|+10y/rememb +er me] login=Login (submit) POST http://perlmonks.org/index.pl node_id=131 (hidden) foo=Refresh (submit) POST http://perlmonks.org? node_id=325590 (hidden) displaytype=display (hidden) vote=<UNDEF> (radio) [0/TCP|1/UDP|2/ICMP|3/IPX| +4/SMB|5/TFTP|6/SMTP|7/NNTP|8/HTTP|9/WAP|10/SOAP] <NONAME>=Vote (submit)

    xoxo,
    Andy