You can't exactly do that. When you test a web application you're testing its responses to GET/HEAD/POST/ETC and that it responds to them correctly with good headers etc. To test web applications you necessarily have to test the transport layer with it and doing that without a webserver of some kind implies writing code that would mimic a webserver's behavior which is goofy (well, not goofy but why we have the stuff Corion mentioned).

I understand your goal though -- it's the unit versus app test problem -- and Catalyst::Controller::REST might fit (part of) the bill. It can be set up so that accept headers dictate how the response is returned. So your tests, for example, could say they'll only accept YAML and your controllers which serve nice XHTML for browsers (which say they accept it) would serve the same stash data that builds the template as YAML instead.

I think in the end though you really have to test the web app directly, your underlying code is stuff like DBI.pm and URI.pm which is well tested already, and if you have JS you'd best use Selenium (which writes 90% of the tests automatically) so starting with a pure unit/in:out testing approach might only (probably will, I'd say) end up duplicating work and making tests redundant.


In reply to Re: Web testing without the web server. by Your Mother
in thread Web testing without the web server. by kyle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.