After (actually right now during) attending the talks on
CGI::Application, with all the testing talks and that people are
interested in how to test CGI::Application applications, I thought to
share what I'm currently doing.
HTTP::Server::Simple is a module by Jesse Vincent. It uses only
modules that are included with Perl to provide a basic webserver,
that works really well for testing.
Currently I'm trying to get Devel::Cover to work with the
HTTP::Server::Simple::CGI server in order to test coverage fo the
webapp from a users point of view.
I've included an example of a test below (I can add this to the Wiki
if there is interest):
use Test::More tests => 2;
use Test::WWW::Mechanize;
use strict;
use warnings;
# Setup a server to run the CGI::App Application
my $server=CGIAppServer->new;
my $pid=$server->background;
ok($pid,'HTTP Server Started');
# If something goes wrong, make sure to stop the HTTP server.
sub cleanup { kill(9,$pid) }
$SIG{__DIE__}=\&cleanup;
# Begin Testing.
my $mech=Test::WWW::Mechanize->new;
$mech->get_ok('http://localhost:8080/','HTTP Get Index');
cleanup();
{
package CGIAppServer;
use base 'HTTP::Server::Simple::CGI';
use MyCGIApp;
sub handle_request {
my ($self, $cgi) = @_;
return MyCGIApp->new->run;
}
1;
}
---
Shawn Sorichetti
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]