I've started looking closely into Apache::Test perl-framework,
inspired by Geoffrey's brief introduction for its sample usage in
Apache::Clean. 

Well, Apache::Test looks really cool, providing me sophisticated
and robust way to test Apache based applications.

Without it I've been doing it with a little dirty shell-script
(kill httpd, generate httpd.conf file and start up via
non-privileged port, then dump mysql database and restore testing
datas into it, etc.)

It'll reduce my work on it. Great.

Well, (at least now) as for my web application testing, I don't
like to use Apache::Test(Util|Request)? Because:

1) I love to do testing with Test::More's utility functions. I'd
just get accustomed to it.

2) shortcut like GET_BODY seems handy, but in many times we need
more complicated testing for web applications (like HTTPUnit in
Java), which we've done by directly using LWP::UserAgent,
HTTP::Request::Common, HTML::LinkExtor etc.


So current test code of mine seems like this:

  use strict;
  use Test::More 'no_plan';
  use LWP::UserAgent;
  use HTTP::Cookies;
  use HTTP::Request::Common;
  use HTML::Form;
  
  # import() does harm, thus "require" 
  require Apache::TestRequest;
  sub url_for { goto &Apache::TestRequest::resolve_url }

  # set up my own user-agent  
  my $ua = LWP::UserAgent->new;
  $ua->cookie_jar(HTTP::Cookies->new);

  my $req = GET url_for '/index.pl';
  my $res = $ua->request($req);
  like $res->content, qr/welcome/;

  # parse forms in html, fill in form and submit
  my $form = HTML::Form->parse($res->content, $req->url);
  $form->value(name => 'foo');
  my $req2 = $form->click;
  # ...

At least I'm happy with it ;). But if you have any suggestions for
it. I'd appreciate it.

Thanks!

--
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>

Reply via email to