[Chicago-talk] Automated testing of web apps?

Jonathan Rockway jon at jrock.us
Mon Feb 26 17:15:27 PST 2007


On Monday 26 February 2007 11:07, Alan Mead wrote:
> An upcoming Perl web application is going to need some testing and I'd
> like to automate it. This (testing) is not like anything that I've done
> previously... Does anyone have suggestions about the right module,
> helpful articles, etc.?

The standard perl way of testing web applications is Test::WWW::Mechanize.  
Mech gives you an web-browser-like interface that looks something like:

   $mech->get_ok('http://localhost/foo.html');
   $mech->content_contains('this is the foo page!');
   $mech->reload();
   $mech->content_contains('this is the foo page RELOADED!');
   @links = $mech->followable_links;
   # etc.

Note that there isn't an actual web browser involved; everything is done 
through LWP::UserAgent.  Oh, and the author reads this list, so if you have 
questions you'll probably get a quick answer. :)

Selenium is like Mech, except the tests pop up a real web browser (Firefox or 
IE) and run the tests inside the browser.  This is great when you're testing 
javascript, but pretty-durn-slow compared to Mech.  An advantage is that you 
can write tests interactively in the Selenium IDE and then incorporate those 
tests in your normal tests suite.  The IDE is good for recording client 
testing so you can reproduce bugs that they find as many times as it takes to 
get the issue fixed.

Something to keep in mind, though, is that you probably don't want to do all 
of your tests via mech or selenium.  If your application is well-structured, 
you should be able to easily test individual components.  Some helpful 
modules in this department are Test::MockObject (for faking parts of your app 
that you don't want to test) and Test::Class for unit testing classes.  If 
your web application framework of choice doesn't come with a test server, 
then you'll want to read up on Apache::Test.  (Now's a good time to mention 
that Catalyst applications are extremely easy to test; you can use 
Test::Catalyst for basic get/post stuff, Test::WWW::Mechanize::Catalyst if 
you want to use mech, and Test::WWW::Selenium::Catalyst if you want selenium.  
Those modules take care of the details for you, so you can just write the 
tests.)

> More specifically, beyond the usual feature-based testing, I'll need to
> stress test it to demonstrate scalability. 

This is a little different from functionality testing.  You'll probably need 
to do it "manually" with a tool like siege.

http://www.joedog.org/JoeDog/Siege

> Testing the app will require 
> authentication but not SSL (not in v1.0, anyway).  For expediency, I'll
> use an Apache layer for authentication initially, with the possibility
> of a cookie-based approach later.

Mech will handle both cookies and SSL.

Regards,
Jonathan Rockway
-- 
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;


More information about the Chicago-talk mailing list