[Pdx-pm] testing simulated CGI input

Greg Minter gminter at hevanet.com
Mon Sep 13 16:33:43 CDT 2004

 >  i have a module which validates CGI parameters. i have a test suite,
 >most of which is straightforward. you can pass the module parameters
 >yourself (easy to test); if you ask nicely, it will get the parameters
 >from CGI.pm directly.

 >and i wonder, more generally, if anyone knows of a better way to do this?

  Here is the method I use to test cgi programs:

  Each page has a 'dispatcher' sub which takes a CGI object
and returns the resulting HTML page. The only thing the .cgi
program does is call the dispatcher:


use CGI;
use my_page;

my ($html);

$html = my_page::->dispatch( CGI::->new);

print "Content-Type: text/html\n\n";
print $html;

  My tests for each module are bundled together in a single program.
This test program can simulate cgi processes by calling the same sub:

# test n
$cgi = new CGI ({..test parameters.. });
$html = my_page::->dispatch($cgi);

# test html page and side effects

  That's all there is to it. No web server or system calls are needed.
  You said that your tests are in separate files. One way to run all of them
would be to change them into perl modules. Then you could call them from
a single perl program.

  I hope this helps,

More information about the Pdx-pm-list mailing list