You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@httpd.apache.org by Stas Bekman <st...@stason.org> on 2002/03/09 06:16:28 UTC

Re: use Apache::Test on Web Application Testing

Tatsuhiko Miyagawa wrote:
> 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:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Re: use Apache::Test on Web Application Testing

Posted by Tatsuhiko Miyagawa <mi...@edge.co.jp>.
At Sun, 10 Mar 2002 00:03:36 +0800,
Stas Bekman wrote:
> > That's the exact point where we don't agree with each other, IMO. I
> > like to make combination of "Simple" modules, and don't like "All in
> > One" package. (Well, Test::More is going into core from perl-5.7, and
> > even before 5.6 it's very easy to install)
> 
> So nothing prevents you from using Test::More, isn't it?

Exactly.

> sure, I'm not against it. You are talking about using extra modules with 
> Apache::Test, to write tests in 3rd party modules. You aren't talking 
> about mod_perl core tests using Test::More, right?

Yes. Apache-Test is self-contained and works best in httpd/mod_perl
core testing, but we can also use it as "sandbox httpd setup tool",
which is useful in writing acceptance live tests. That's what I wanted
to say.


--
Tatsuhiko Miyagawa 


Re: use Apache::Test on Web Application Testing

Posted by Stas Bekman <st...@stason.org>.
Tatsuhiko Miyagawa wrote:
> At Sat, 09 Mar 2002 13:16:28 +0800,
> Stas Bekman wrote:
> 
> 
>>>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 :)
>>
> 
> That's the exact point where we don't agree with each other, IMO. I
> like to make combination of "Simple" modules, and don't like "All in
> One" package. (Well, Test::More is going into core from perl-5.7, and
> even before 5.6 it's very easy to install)

So nothing prevents you from using Test::More, isn't it? Consider the 
only wrapper that we have -- Apache::TestUtil::t_cmp as Test::Simple :)

> In addition, tests we write are not only limited in httpd one. For
> example, we should write unit tests for business logic classes with
> Test::More. Writing tests with various tools will go into just a
> little confusion. We want consistency in them, for the cost of
> learning, etc.

sure, I'm not against it. You are talking about using extra modules with 
Apache::Test, to write tests in 3rd party modules. You aren't talking 
about mod_perl core tests using Test::More, right?


_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Re: use Apache::Test on Web Application Testing

Posted by Tatsuhiko Miyagawa <mi...@edge.co.jp>.
At Sat, 09 Mar 2002 13:16:28 +0800,
Stas Bekman wrote:

> > 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 :)

That's the exact point where we don't agree with each other, IMO. I
like to make combination of "Simple" modules, and don't like "All in
One" package. (Well, Test::More is going into core from perl-5.7, and
even before 5.6 it's very easy to install)

In addition, tests we write are not only limited in httpd one. For
example, we should write unit tests for business logic classes with
Test::More. Writing tests with various tools will go into just a
little confusion. We want consistency in them, for the cost of
learning, etc.

> >   # import() does harm, thus "require" 
> >   require Apache::TestRequest;
> >   sub url_for { goto &Apache::TestRequest::resolve_url }

These lines are the things what I need from httpd-test
framework. Without this, I should get Ports etc from environment
variable or something like that. So, thanks for it ;)

> so you have no need to work directly with LWP.

Yes. But for dynamically generated cookies or web forms, HTTP::Cookies
or HTML::Forms greatly helps. So I use these modules directly.

Though supporting these API with Apache::TestUtils may not be hard
one, but again, I like to make combination of simple modules.

Well, recently there's WWW::Automate module on CPAN, which has a very
close idea to my testing code. I should consider using this instead.

TMTOWTDI :)


-- 
Tatsuhiko Miyagawa