[cgiapp] Testing Methods

Michael Peters mpeters at plusthree.com
Mon May 18 10:18:25 EDT 2009


Mike Tonks wrote:

> Can anyone recommend a method or point me to some examples for testing
> CGI::App run modes?

For basic tests you can just instantiate your classes, call run and get the 
output using the CGI_APP_RETURN_ONLY environment variable. Then you can use 
things like Test::HTML::Content to make sure it looks like what you want.

But this only really works for light testing. If you really want to make sure 
your application works you should test it using the same web server you're going 
to use in production. And then you can test it just like any other web app with 
  Test::WWW::Mechanize and friends.

> Our app is getting ever more complex and could really do with some
> automated tests.  I'm able to build tests against the MCV 'model'
> classes, but not the controllers or views (never mind the ajax!).

Ajax is trickier. Do you just want to test that your server returns the right 
things in Ajax mode? It's pretty easy to use Mechanize to test things like HTML 
snippets and JSON. But it gets more difficult if you actually want to run your 
Javascript. For that you'll need something like Selenium or Windmill.

-- 
Michael Peters
Plus Three, LP



More information about the cgiapp mailing list