I have the opportunity to write a web application from scratch, and I really want it to be as testable as possible, and I'd like to hear from the monks about how to do that.

What I'd really like to avoid is some variant on full blown web client to web server communication for testing. I don't want to write Selenium scripts (though I might, just to check the templates), and I don't want to spawn a baby web server when I'm testing (though a baby database doesn't bother me).

The approach I'm considering right now is to write the controllers with an interface that simply takes CGI-ish parameters and returns data ready for the Template. So: data structure in, data structure out.

The actual Catalyst controller can then be a thin wrapper around these testable components.

I see that CGI has a save() method, and it can load its save files, but it appears those save files don't include things from the environment like the remote IP address, browser's user agent string, or other things I might want to use to taylor content. Because of this, I think I need to do more work to "mock" parameters to a controller. Just creating a new CGI object from passed in parameters isn't enough.

Has anyone else out there faced this, written this, done this? Is there an article on the best way to go about what I'm talking about? I have the chance to do this right from the start, so any ideas would be welcome!


In reply to 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.