[Catalyst] Detecting Incorrectly Displayed Page (Generating andVisiting URLS automatically ?)

Peter Edwards peter at dragonstaff.com
Mon Feb 4 08:01:46 GMT 2008


>Sindharta wrote:
>I am currently doing some tests with my application and I am wondering if
>there is any efficient and effective way to know if pages which should be
>displayed correctly are actually being redirected to another page, such as
>"404 - Data Not Found", because of some logic or data mismatches ?
>
>One idea that came to my mind is by generating URLs and visiting generated
>URLs by our program, and check the used template file. For example, if we
h>ave 3 records, with '1','2','3' as their ids,  we want to do a loop to
>visit each generated URL and look if they are displayed correctly by
>generating an output such as this:
>
>URL                    ID   Used Template
>---                     --   ------------
>localhost/key/1     1    index.tt2
>localhost/key/2     2.    error.tt2
>localhost/key/3     3.    index.tt2

You are proposing testing based on which template is used. The error.tt2
template might be used for any number of reasons, some of them good as you
may do some failing tests that should fail.

I'd suggest a combination of testing at different levels, both 
"white box" http://en.wikipedia.org/wiki/White_box_testing
and "black box" http://en.wikipedia.org/wiki/Black_box_testing

you should have unit tests
http://en.wikipedia.org/wiki/Unit_testing

integration tests
http://en.wikipedia.org/wiki/Integration_testing

and regression tests
http://en.wikipedia.org/wiki/Regression_testing


you can achieve this by

1) Throw exceptions at different levels.
If your Model Model::Book (for example) fails to read book with record id 1,
throw an exception. If your controller logic detects an error, throw an
exception. Likewise inside your templates (if using Template::Toolkit) you
can throw an error if you detect inconsistent data.
http://search.cpan.org/search?query=catalyst%3A%3Aexception

2) Write web application tests that perform a logical sequence of login,
create records, follow links, test error conditions. Test::WWW::Mechanize
lets you check HTTP response status, e.g. 200 OK, 301/302 found redirect,
4xx error, and also the content of rendered page. So in your example, you
might look for string "record 1 not found" in the resulting HTML.

See

Catalyst::Manual::Tutorial::Testing
http://search.cpan.org/search?query=Catalyst%3A%3AManual%3A%3ATutorial%3A%3A
Testing&mode=all 

Test::WWW::Mechanize::Catalyst
http://search.cpan.org/search?query=Test%3A%3AWWW%3A%3AMechanize%3A%3ACataly
st&mode=all


Also

http://catwiki.toeat.com/fromtrac/testing.highlight 


Regards, Peter
http://perl.dragonstaff.co.uk





More information about the Catalyst mailing list