I've started looking closely into Apache::Test perl-framework,
inspired by Geoffrey's brief introduction for its sample usage in
Apache::Clean.
Sorry Tatsuhiko, this email seemed to fall between chairs :(
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.
cool!
modperl-2.0/docs/devel/testing/testing.pod provides an extensive documentation for Apache::Test. It should answer most of the questions. It's definitely incomplete. So if you see something missing please let us know.
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.
Apache::Test's motto is to be self-contained and Test::More is not a part of the perl core. Therefore if you need any of Test::More functionalities we can add these to Apache::TestUtil. Either tell us what you want ported or send a patch :)
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.
from testing.pod:
=head2 Multiple User Agents
By default the C<Apache::Test> framework uses a single user agent which talks to the server (this is the C<LWP> user agent, if you have C<LWP> installed). You almost never use this agent directly in the tests, but via various wrappers. However if you need a second user agent you can clone these. For example:
my $ua2 = Apache::TestRequest::user_agent()->clone;
As for cookies, I've started adding the test suite for Apache::Request so here is cookie.t:
use Apache::Test;
use Apache::TestUtil; use Apache::TestRequest qw(GET_BODY); use HTTP::Cookies;
plan tests => 1;
my $location = "/TestApReq::cookie";
{ # basic param() test my $test = 'basic'; my $key = 'apache'; my $value = 'ok'; my $cookie = qq{\$Version="1"; $key="$value"; \$Path="$location"}; ok t_cmp(qq{"$value"}, GET_BODY("$location?test=$test&key=$key", Cookie => $cookie), $test); }
so you have no need to work directly with LWP. Hope this helps ;)
_____________________________________________________________________ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://ticketmaster.com http://apacheweek.com http://singlesheaven.com http://perl.apache.org http://perlmonth.com/