r.rafique has asked for the wisdom of the Perl Monks concerning the following question:

OK, my main objective is to write unit tests for a Fast CGI perl script that works with both session and cookies. Problem: How do I simulate the web-server behaviour while calling my perl script so that it can be called times with session data and cookies intact somewhere. I imagine I'll use Thus::MockObject somehow for can't figure. Any pointers or guidance will be appreciated. Thanks.

Replies are listed 'Best First'.
Re: How to simulate a web server behaviour
by samtregar (Abbot) on Jun 23, 2008 at 17:16 UTC
    I've had a few less-than-successful experiences with Test::MockObject. The tests were hard to write and they didn't uncover real bugs because they just weren't that realistic.

    I'd encourage you to build a test harness that runs a real web server talking to your real FCGI script. Then you can hit that real server (probably running on a high port) with Test::WWW::Mechanize. You can look at Apache::Test for inspiration or keep it simple. I've done this for web apps and for SMTP clients (using Net::SMTP::Server here). It's a pain to get the start/stop behavior right but once you do it's all downhill and your tests tend to find real bugs. And that's the whole point, isn't it?

    -sam

Re: How to simulate a web server behaviour
by dragonchild (Archbishop) on Jun 23, 2008 at 18:09 UTC
    Take a look at what Catalyst does for testing.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: How to simulate a web server behaviour
by andreas1234567 (Vicar) on Jun 24, 2008 at 06:09 UTC
    Try Selenium. There is a Perl client called WWW::Selenium, and a Firefox plugin called Selenium IDE.
    --
    No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]