That depends on what you want the tests to cover.

You implied that you use LWP in there, so I assume your layout is layered.

Let me make a guess of what an 'internet client' might look like:

In my opinion if you're going to test the software, you ought to test that each part works as expected, and also test that they work toegether as a whole - unit testing and integration testing.

If you're at the unit testing stage I suggest you ignore complicated webserver setups, and simply use Test::MockObject to make sure that each layer behaves properly based on some precanned output from the mocked layer underneath it.

If you're doing a larger scale test for the way the things behave together, then it's a question of what's easier, and breaks less.

If you can easily mock server side errors, connection drops, edge-case data, and all the other stuff testing should help you make sure you cover by mocking a webserver, by all means go for it. There are many ways to write a simple HTTP server on CPAN.

If it looks like it will be simple to mock LWP, on the other hand, go with that. There's no cost quality wise, since LWP is not your code - it's tested anyway. This has the advantage of being more readable and simpler, since there are no multiple processes or invocations involved. It might even be easier to generate truely odd cases, which is valuable for test cases based on bug reports.

The cost is that you don't really know whether your layers use LWP properly, since "real" LWP is not involved. I don't think this is the same as your rationalization for why it's the least desirable - 100% coverage is often too much. The effort spent getting from 90 to 100 is probably going to be better spent on alternative methods of quality control.

I would say that my best advice is to try and balance a throwaway HTTP server with mock objects. As for example.com and friends - this might introduce false positives into your test suite, if the net is down, for example. If you do go ahead with it, make sure to query the user before initiating a connection though (A good place for this is Makefile.PL).

-nuffin
zz zZ Z Z #!perl

In reply to Re: ISO fixtures for testing internet client code by nothingmuch
in thread ISO fixtures for testing internet client code by tlm

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.