Mojo, specifically Mojolicious, is aces when it comes to this kind of testing.

In Mojolicious, you can create routes, which are essentially regexes that match URLs, with a sub associated with each one that gets called. It's usually a pretty simple process to create a route for each of the server states you want to generate (even 404s, 500 server errors, timeouts, etc.) the output you want at the client from text. This means the Mojo mock server is dumb as a bag of hammers, but can return the right thing for the right URL.

You can now write a client that responds properly to this mock server; once that's working, you can then test the client against the real server as a backstop. If the test vs. the real server fails, you can now see whether it's because the server's doing something unexpected or not by rerunning the test vs. the mock server. If that passes but the real server fails, you know that the problem's in the data that the client is getting, not the client itself (unless your mock server is seriously out of spec vs. the real server; continuous integration will help keep this from happening, as you'll see any changes as early as possible).

The nice thing is that as long as you make sure that any server output changes (note I did not say "server changes" - as long as the output is the same, the mock server doesn't need an update, no matter how the backend is shuffled - using an MVC model in the server will help with this a LOT).

As far as testing generated methods goes, I would - but only because any code I have actually tested and verified to work is yet another thing I don't have to look at when debugging a problem. Investing 5 or 10 minutes initially turns into a lot of savings each time you have to debug something that might be broken if the data you wanted your method to store wasn't stored properly.


In reply to Re: Testing perl modules that rely on remote data by pemungkah
in thread Testing perl modules that rely on remote data by worr

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.