You said: "Does this make me a bad person?"

Not necessarily bad, just cautious -- it doesn't feel right -- and pragmatic, you went and asked for a second opinion.

When I am writing tests I try as much as possible to get into the 'assertion' mind-set -- is the value returned from my method equal to 'X'? Simple, yes/no tests.

If my method has side-effects (I call it with Y, I get X back, and by the way, the file is now readable....), I'd think about alternative ways of testing my side-effect. Say, create a file without read-permission, call my routine that sorts out the permissions bits to what I want. Then open the file for reading and check the return value from open() ('true' on success, and 'false' on failure). This way you could write a binary test for a successful open. Any function that you can use the  or die ... idiom on is susceptible to this approach.

If you haven't run across Ian Langworth and cromatic's book Perl Testing: A Developer's Notebook, you should. They have a number of recipes for testing most everything under the Sun using Perl and the Test Anything Protocol.

----
I Go Back to Sleep, Now.

OGB


In reply to Re: Philosophical question about testing by Old_Gray_Bear
in thread Philosophical question about testing by rastoboy

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.