I've started testing more seriously lately, and came across what must be a pretty common test design issue. (Which means: I'd be happy to get either a simple answer, or a pointer to a FAQ that has more answers to questions of this sort.)

My application validates some record-based input it receives, and before doing any heavy processing on it generates a report on validation errors it may have encountered. The report is textual and should go to a file specified by the user (e.g. via a command line switch, with some reasonable default).

I'm testing the validation phase now, and want to take advantage of in-memory files (5.8.0 and onwards support open $fh, '>', \$file_in_ram) so that my test doesn't have to start messing with real files. I can make the file handle a field in the object I'm testing, but I can't figure out an elegant way to keep the file itself around and accessible to the test. Not any way that isn't horrendously ugly, anyway. Like for example adding a member to the object that is populated only during tests.

What's a reasonable way to approach this? Should I just forget it, write out the file, and read it back? (One reason I didn't want to do that is that I may want to inspect my data before closing it, and don't want to be bitten by buffering issues. Now that I think of it, though, the same issues can exist with an in-memory file.)


In reply to Test-specific members by gaal

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.